Skip to main content
Back to Blog DevOps

Docker for Laravel Developers: From Development to Production

Abdelrahman Shrief
Abdelrahman Shrief February 09, 2026
5 min read

Why Docker?

Docker ensures consistency across development, staging, and production environments. No more "it works on my machine" issues.

Development Setup with Laravel Sail

Laravel Sail provides a Docker-based development environment:

# Install Sail in existing project
composer require laravel/sail --dev

# Publish Sail configuration
php artisan sail:install

# Start the containers
./vendor/bin/sail up -d

# Run artisan commands
./vendor/bin/sail artisan migrate
./vendor/bin/sail artisan test

# Stop containers
./vendor/bin/sail down

Production Dockerfile

For production, you'll want an optimized multi-stage build:

# Build stage
FROM composer:2 as build

WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --no-scripts --prefer-dist

COPY . .
RUN composer dump-autoload --optimize

# Production stage
FROM php:8.3-fpm-alpine

# Install dependencies
RUN apk add --no-cache \
    nginx \
    supervisor \
    && docker-php-ext-install pdo pdo_mysql opcache

# Copy application
WORKDIR /var/www/html
COPY --from=build /app /var/www/html

# Configure PHP
COPY docker/php.ini /usr/local/etc/php/conf.d/app.ini

# Configure Nginx
COPY docker/nginx.conf /etc/nginx/nginx.conf

# Configure Supervisor
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Set permissions
RUN chown -R www-data:www-data /var/www/html/storage

EXPOSE 80

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Docker Compose for Services

Orchestrate your application stack with docker-compose:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:80"
    environment:
      - APP_ENV=production
      - DB_HOST=mysql
      - REDIS_HOST=redis
    depends_on:
      - mysql
      - redis
    networks:
      - app-network

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: laravel
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - app-network

  redis:
    image: redis:alpine
    networks:
      - app-network

  queue:
    build:
      context: .
      dockerfile: Dockerfile
    command: php artisan queue:work --sleep=3 --tries=3
    depends_on:
      - mysql
      - redis
    networks:
      - app-network

networks:
  app-network:
    driver: bridge

volumes:
  mysql-data:

Conclusion

Docker simplifies deployment and ensures consistency across all environments. Start with Laravel Sail for development, then create optimized production images.

Abdelrahman Shrief
Abdelrahman Shrief Senior Backend Developer

Share this post

Need Help With Your Project?

Let's discuss how I can help bring your ideas to life with expert backend development.

Get in Touch