FROM php:8.1-fpm # Set working directory WORKDIR /var/www/html # Install system dependencies RUN apt-get update && apt-get install -y \ git \ curl \ libcurl4-openssl-dev \ pkg-config \ libonig-dev \ libxml2-dev \ libzip-dev \ zip \ unzip \ libfreetype6-dev \ libjpeg62-turbo-dev \ libpng-dev \ libxpm-dev \ libvpx-dev \ supervisor \ nginx \ nodejs \ npm \ && rm -rf /var/lib/apt/lists/* # Install PHP extensions RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-xpm \ && docker-php-ext-install -j$(nproc) \ curl \ pdo_mysql \ mbstring \ exif \ pcntl \ bcmath \ gd \ zip \ dom \ xml # Install Redis extension RUN pecl install redis \ && docker-php-ext-enable redis # Install Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # Copy only composer and package files first for caching COPY composer.json composer.lock package.json package-lock.json ./ # Install PHP dependencies (cached if lock file unchanged) RUN composer install --optimize-autoloader --no-dev --no-interaction # Install Node dependencies (cached if lock file unchanged) RUN npm ci --only=production # Now copy the full Laravel application code COPY . . # Build assets and create storage link RUN npm run production && \ php artisan storage:link # Set proper permissions (for production only do this once) RUN mkdir -p storage/logs \ && mkdir -p storage/framework/{cache,sessions,views} \ && mkdir -p storage/app \ && mkdir -p bootstrap/cache \ && chown -R www-data:www-data /var/www/html \ && chmod -R 775 storage \ && chmod -R 775 bootstrap/cache \ && chmod -R 755 public # Nginx config COPY ./docker/nginx.conf /etc/nginx/sites-available/default # Supervisor config COPY ./docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Expose web port EXPOSE 80 CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]