Production-ready Docker environment for Laravel โ dev, staging and prod in one place.
A complete, battle-tested Docker setup that goes further than Laravel Sail:
| Feature | Laravel Sail | This starter |
|---|---|---|
| Dev environment | โ | โ |
| Staging environment | โ | โ |
| Production environment | โ | โ |
| Multi-stage Dockerfile (dev/prod) | โ | โ |
| CI/CD with GitHub Actions | โ | โ |
Dynamic .env from GitHub Environments |
โ | โ |
| Releases system + rollback | โ | โ |
| MySQL 8.4 or PostgreSQL 16 (switchable) | โ | โ |
| Xdebug 3 pre-configured | โ | โ |
| Opcache + JIT in production | โ | โ |
| Mailpit (fake SMTP) | โ | โ |
| MinIO (local S3-compatible storage) | โ | โ |
| Laravel Reverb (WebSocket server) | โ | โ |
| SSL/HTTPS + cert generator | โ | โ |
| Queue worker + Scheduler | โ | โ |
| Security headers in Nginx | โ | โ |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Nginx (stable) โ
โ Security headers ยท Gzip ยท Cache โ
โ HTTP + HTTPS (app-ssl.conf) โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastCGI
โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PHP 8.4-FPM (Alpine) โ
โ Extensions: gd, intl, bcmath, redis, ... โ
โ DEV: Xdebug 3 โ
โ PROD: Opcache + JIT + entrypoint cache โ
โโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโผโโโโโโโ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโ
โ MySQL 8.4 โ โ Redis 7 โ
โ OR โ โ Cache ยท Queue ยท Sessions โ
โ PostgreSQL 16 โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ (via profiles) โ
โโโโโโโโโโโโโโโโโโ
โโ DEV only (via profiles) โโโโโโโโโโโโโโโโโโโโโโ
Mailpit (SMTP) ยท MinIO (S3) ยท Reverb (WS)
Queue Worker ยท Scheduler ยท Vite dev server
.
โโโ .docker/
โ โโโ php/
โ โ โโโ Dockerfile # Multi-stage: development | production
โ โ โโโ php.ini # Dev config (debug on, opcache off)
โ โ โโโ php-prod.ini # Prod config (opcache + JIT)
โ โ โโโ www.conf # PHP-FPM pool
โ โ โโโ xdebug.ini # Xdebug 3 (dev only)
โ โ โโโ entrypoint.sh # Prod: config:cache, route:cache...
โ โโโ nginx/
โ โ โโโ Dockerfile
โ โ โโโ conf.d/app.conf # Gzip, security headers, PHP-FPM
โ โโโ cron/Dockerfile # Laravel Scheduler
โ โโโ mysql/init/ # MySQL init scripts
โ โโโ pgsql/init/ # PostgreSQL init scripts
โโโ .github/
โ โโโ workflows/
โ โ โโโ ci.yml # Tests on PR (MySQL + PostgreSQL)
โ โ โโโ deploy.yml # Build GHCR image โ SSH deploy
โ โ โโโ rollback.yml # One-click rollback from GitHub UI
โ โโโ ISSUE_TEMPLATE/ # Bug + Feature request templates
โ โโโ pull_request_template.md
โโโ scripts/
โ โโโ deploy.sh # Releases by git SHA, current symlink
โ โโโ rollback.sh # Instant rollback to previous SHA
โโโ docker-compose.yml # Base services
โโโ docker-compose.dev.yml # + Xdebug, Mailpit, Vite
โโโ docker-compose.staging.yml # Prod images, resource limits
โโโ docker-compose.prod.yml # Prod images, strict limits, JSON logging
โโโ .env.example
โโโ Makefile # Shortcuts for all operations
Full step-by-step guide โ QUICKSTART.md
git clone https://github.com/serwin35/docker-laravel-starter.git my-project cd my-project cp .env.example .env make laravel-new # installs Laravel inside the container make setup DB=mysql # build + up + key:generate + migrate
# Inside your existing Laravel project directory: curl -fsSL https://github.com/serwin35/docker-laravel-starter/archive/refs/heads/main.tar.gz \ | tar xz --strip-components=1 \ --exclude='docker-laravel-starter-main/README.md' \ --exclude='docker-laravel-starter-main/LICENSE' \ --exclude='docker-laravel-starter-main/.git' # Merge .env.example Docker variables into your existing .env make up DB=mysql make migrate
App available at http://localhost:80
Switch between MySQL and PostgreSQL via Docker profiles:
make up DB=mysql # mysql:8.4 make up DB=pgsql # postgres:16-alpine
Update .env accordingly:
# MySQL DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 # PostgreSQL DB_CONNECTION=pgsql DB_HOST=pgsql DB_PORT=5432
# First run make laravel-new # Install fresh Laravel inside the container (no local PHP) make setup DB=mysql # Build + up + install + key:generate + migrate # Environment management make up DB=mysql # Start (DB=mysql|pgsql, ENV=dev|staging|prod) make down # Stop all containers make ps # Container status make logs # Tail logs (ARGS=php to filter one service) make shell # bash inside the php container # Laravel make artisan ARGS="make:model Post -mcr" make composer ARGS="require spatie/laravel-permission" make migrate make seed make fresh # migrate:fresh --seed make tinker make cache-clear # Clear all Laravel caches # Testing make test make coverage make lint # PHP Pint make analyse # PHPStan # Frontend make npm-dev # Vite dev server with hot-reload make npm-build # Production asset build make npm ARGS="add alpinejs" # Database CLI make db-mysql make db-pgsql make db-redis # Optional services (require profiles) COMPOSE_PROFILES=minio,mysql make up # + MinIO S3 storage COMPOSE_PROFILES=reverb,mysql make up # + Laravel Reverb WebSocket COMPOSE_PROFILES=npm,mysql make up # + Vite dev server in background
One of the key features of this starter is the git SHA-based releases system โ the same pattern used by Deployer, Capistrano and Envoyer, implemented in pure Bash + Docker.
/var/www/myapp/
โโโ releases/
โ โโโ a1b2c3d4.../ โ two weeks ago
โ โโโ e5f6g7h8.../ โ previous deploy (available for rollback)
โ โโโ i9j0k1l2.../ โ active deploy โ current points here
โ
โโโ shared/
โ โโโ .env โ shared โ CI uploads before each deploy
โ โโโ storage/ โ logs, uploads, cache โ persistent across releases
โ
โโโ current -> releases/i9j0k1l2... โ symlink, switched atomically
- Creates
releases/{git-sha}/directory - Extracts code via
git archive - Symlinks
shared/.envandshared/storage/ - Switches
currentsymlink atomically (mv -T) โ zero downtime - Runs
docker compose up -d --waitโ containers start with new code - Runs
php artisan migrate --force - Prunes old releases (keeps last 5 by default)
Via GitHub UI (recommended):
Actions โ Rollback โ select environment โ Run workflow
Via SSH on the server:
# Roll back to the previous release automatically: DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh # Roll back to a specific commit: GIT_SHA=e5f6g7h8 DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh
Rollback is instant โ it only switches the symlink and restarts containers. No image pull needed.
Each release directory is named after the git commit SHA, so you can always trace exactly what code is running: git show i9j0k1l2.
make up # docker compose -f base -f devIncludes: Xdebug, Mailpit (http://localhost:8025), Vite dev server, bind mounts.
make up ENV=staging DB=mysql
Production PHP image, resource limits (1 CPU / 512M RAM).
make up ENV=prod DB=mysql
Production image, strict limits (2 CPU / 1G RAM), JSON logging, restart: always.
Pull Request โ Lint (Pint) โ PHPStan โ Tests on MySQL โ Tests on PostgreSQL
develop โ dev server
staging โ staging server
main โ production server (+ required reviewers)
1. npm run build (frontend assets)
2. Build PHP image (prod) (code + vendor baked in)
3. Build Nginx image (prod) (public/ assets baked in)
4. Push both to GHCR
5. Dynamic .env built from GitHub Environment vars/secrets
6. SSH โ run deploy.sh:
- Create releases/{git-sha}/
- Symlink shared/.env + shared/storage/
- Switch current โ new release (atomic)
- docker compose up -d --wait
- php artisan migrate --force
7. Smoke test: GET /up โ 200 OK
# Via GitHub UI (recommended): Actions โ Rollback โ choose env โ Run workflow # Via SSH: DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh # To specific commit: GIT_SHA=abc1234 DEPLOY_PATH=/var/www/app ENVIRONMENT=prod bash scripts/rollback.sh
Create three environments: dev, staging, prod in Settings โ Environments.
Required per environment:
| Type | Name | Description |
|---|---|---|
| Secret | SSH_HOST |
Server IP or hostname |
| Secret | SSH_USER |
Deploy user |
| Secret | SSH_KEY |
Private SSH key |
| Var | SSH_PORT |
SSH port (default 22) |
| Var | DEPLOY_PATH |
Absolute path on server |
| Var | APP_URL |
For smoke test |
| Var | DB_PROFILE |
mysql or pgsql |
| Secret | APP_KEY |
Laravel app key |
| Secret | DB_PASSWORD |
Database password |
All other vars/secrets are automatically written to .env โ no manual enumeration needed.
Pre-configured for PhpStorm and VS Code on port 9003:
# .env XDEBUG_MODE=debug # step debugging XDEBUG_MODE=coverage # code coverage XDEBUG_MODE=off # disabled (faster)
Contributions are welcome! This project uses GitHub Actions โ your merged PR counts toward the Open Sourcerer achievement.
See CONTRIBUTING.md for guidelines.
Good first issues: github.com/serwin35/docker-laravel-starter/issues?q=label%3A%22good+first+issue%22
Have a question or idea? Use GitHub Discussions.
If this starter kit saves you time โ please star โญ the repo. It helps others discover the project and motivates continued development.
MIT โ free to use in commercial projects.