Laravel Dockerfile Generator: Complete Guide
Laravel Multi-Stage Dockerfile with Composer
Laravel applications depend on Composer for package management. Using a multi-stage build with the official Composer image ensures dependencies are installed in an isolated environment, and only the final vendor directory is copied into the production image.
# Stage 1: Composer
FROM composer:2.6 AS vendor
WORKDIR /app
COPY database/ database/
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
# Stage 2: Runner
FROM php:8.2-apache
WORKDIR /var/www/html
COPY . .
COPY --from=vendor /app/vendor/ ./vendor/
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
EXPOSE 80
CMD ["apache2-foreground"]