FROM php:8.2-fpm-alpine # Install system dependencies RUN apk add --no-cache \ libzip-dev \ postgresql-dev \ libpng-dev \ libjpeg-turbo-dev \ freetype-dev \ oniguruma-dev \ git \ curl \ && docker-php-ext-configure gd --with-freetype --with-jpeg \ && docker-php-ext-install -j$(nproc) \ pdo_pgsql \ pgsql \ opcache \ zip \ bcmath \ gd \ exif \ pcntl # Install Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer WORKDIR /var/www/html # Copy all application files (including your .env) COPY --chown=www-data:www-data . . # Create the missing Helper file RUN mkdir -p app/Helpers && \ echo " app/Helpers/Helper.php # Create ALL Laravel storage directories with proper permissions RUN mkdir -p storage/framework/{cache,sessions,views} \ && mkdir -p storage/logs \ && mkdir -p bootstrap/cache \ && chown -R www-data:www-data storage bootstrap/cache \ && chmod -R 775 storage bootstrap/cache \ && chmod -R 777 storage/framework/sessions \ && chmod -R 777 storage/logs # Verify directories exist (debug step) RUN ls -la storage/framework/ && ls -la bootstrap/ # Install dependencies with --no-scripts first RUN composer install --no-dev --no-interaction --no-progress --optimize-autoloader --no-scripts # Run post-install scripts separately RUN composer run-script post-autoload-dump || echo "Post-autoload dump skipped" # Generate key if not set in .env RUN php artisan key:generate --no-interaction --force || true # Final permission check RUN chmod -R 775 storage bootstrap/cache # Create startup script RUN echo '#!/bin/sh' > /start.sh && \ echo 'if [ "$MODE" = "dev" ]; then' >> /start.sh && \ echo ' echo "Starting in DEV mode with PHP built-in server on port 8000..."' >> /start.sh && \ echo ' php artisan serve --host=0.0.0.0 --port=8000' >> /start.sh && \ echo 'else' >> /start.sh && \ echo ' echo "Starting in PROD mode with PHP-FPM on port 9000..."' >> /start.sh && \ echo ' php-fpm' >> /start.sh && \ echo 'fi' >> /start.sh && \ chmod +x /start.sh EXPOSE 8000 9000 CMD ["/start.sh"]