docker-laravel is a production-inspired local development environment built with Docker Compose. Clone it, run one command, and you have a full LEMP stack up and running — no homebrew conflicts, no version mismatches, no "works on my machine" headaches.
It comes pre-wired with:
- PHP 8.3 FPM behind Nginx
- MariaDB 11.4 for your database
- Redis for cache, sessions, and queues
- Mailpit to catch all outgoing emails locally
- phpMyAdmin for quick DB inspection
- Node.js 22 LTS + Composer 2 as isolated run containers
- GitHub Actions workflows for CI/CD out of the box
Whether you are starting a new Laravel project or onboarding teammates to an existing one, this setup gets everyone to an identical environment in minutes.
| Feature | docker-laravel | Laravel Sail | Laravel Valet |
|---|---|---|---|
| Zero host dependencies | Yes | Yes | No (macOS only) |
| Explicit, version-pinned images | Yes | Yes | N/A |
| MariaDB (not MySQL) | Yes | Optional | No |
| Redis included | Yes | Optional | Via extension |
| Mailpit included | Yes | No (MailHog) | No |
| phpMyAdmin included | Yes | No | No |
| GitHub Actions CI/CD | Yes | No | No |
| Independent of Laravel app itself | Yes | No (installs into project) | No |
| Works on Linux / macOS / Windows | Yes | Yes | No |
| Configurable ports via .env | Yes | Partial | No |
| Service | Image | Default Port | Configurable |
|---|---|---|---|
| PHP-FPM | php:8.3-fpm-alpine |
9000 (internal) | No |
| Nginx | nginx:stable-alpine |
8080 |
APP_PORT |
| MariaDB | mariadb:11.4 |
3306 |
SQL_PORT |
| phpMyAdmin | phpmyadmin/phpmyadmin:latest |
70 |
PMA_PORT |
| Redis | redis:alpine |
6379 |
No |
| Mailpit | axllent/mailpit:latest |
1025 (SMTP), 8025 (UI) |
No |
| Composer | composer:2 |
— (run container) | — |
| Node.js | node:22-alpine |
3000, 3001 (Vite) |
— |
- Docker Desktop (or Docker Engine + Compose plugin on Linux)
- Git
That is all. PHP, Node, Composer — everything runs inside containers.
git clone https://github.com/serwin35/docker-laravel.git my-project
cd my-projectcp .env.example .env
Open .env and adjust any ports if needed (see Environment Variables).
docker compose up -d --build site
# Remove the placeholder src/README.md first rm src/README.md docker compose run --rm composer create-project --prefer-dist laravel/laravel .
To use an existing Laravel project instead, copy your project files into the
src/directory and skip this step.
nano src/.env
Set the database credentials to match what is in your root .env:
DB_CONNECTION=mysql DB_HOST=mysql DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
Set Redis:
REDIS_HOST=redis REDIS_PORT=6379
docker compose run --rm artisan migrate
Your app is now live at http://localhost:8080.
# Install dependencies docker compose run --rm composer install # Update dependencies docker compose run --rm composer update # Add a package docker compose run --rm composer require vendor/package
# Run migrations docker compose run --rm artisan migrate # Rollback migrations docker compose run --rm artisan migrate:rollback # Open Tinker REPL docker compose run --rm artisan tinker # Clear all caches docker compose run --rm artisan optimize:clear # List all routes docker compose run --rm artisan route:list
# Install dependencies docker compose run --rm npm install # Development build docker compose run --rm npm run dev # Production build docker compose run --rm npm run build
# Start the full stack docker compose up -d # Stop the stack (preserves volumes) docker compose down # Stop and remove volumes (full reset) docker compose down -v # View logs docker compose logs -f site # Open a shell inside the PHP container docker compose exec site sh
| Service | URL |
|---|---|
| Laravel Application | http://localhost:8080 |
| phpMyAdmin | http://localhost:70 |
| Mailpit UI | http://localhost:8025 |
| Vite HMR (during dev) | http://localhost:3000 |
All ports are configurable in
.env— see Environment Variables.
The root .env file controls the Docker Compose stack. The src/.env file controls Laravel itself. They are separate.
| Variable | Default | Description |
|---|---|---|
APP_PORT |
8080 |
Nginx HTTP port on your host |
SQL_PORT |
3306 |
MariaDB port on your host |
PMA_PORT |
70 |
phpMyAdmin port on your host |
DB_DATABASE |
homestead |
Database name |
DB_USERNAME |
homestead |
Database user |
DB_PASSWORD |
secret |
Database password |
DB_ROOT_PASSWORD |
secret |
MariaDB root password |
UID |
1000 |
Host user ID (for file permission mapping) |
GID |
1000 |
Host group ID (for file permission mapping) |
If you see Permission denied errors when Laravel tries to write to storage/ or bootstrap/cache/, the container user does not match your host user.
Fix:
# Find your host UID and GID id -u # typically 1000 on Linux id -g # Set them in the root .env UID=1000 GID=1000 # Rebuild the containers docker compose down docker compose build --no-cache docker compose up -d
On macOS with Docker Desktop this is usually not needed because Docker handles user mapping automatically.
Ports 3000 and 3001 are mapped on the npm service by default. Use --service-ports to expose them when running Vite:
docker compose run --rm --service-ports npm run dev
In your vite.config.js, configure the dev server so Vite binds to 0.0.0.0 and the HMR client connects through your host:
import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; export default defineConfig({ plugins: [ laravel({ input: ['resources/css/app.css', 'resources/js/app.js'], refresh: true, }), ], server: { host: '0.0.0.0', port: 3000, hmr: { host: 'localhost', }, }, });
Then visit http://localhost:3000 for live-reloading.
All emails sent from Laravel are captured by Mailpit — nothing reaches the real internet. View them in the Mailpit web UI at http://localhost:8025.
Configure Laravel's src/.env:
MAIL_MAILER=smtp MAIL_HOST=mailpit MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="[email protected]" MAIL_FROM_NAME="${APP_NAME}"
mailpitresolves to the Mailpit container inside the Docker network. No extra configuration needed.
The repository ships with pre-built GitHub Actions workflows. To activate them, add the following repository secrets in Settings → Secrets and variables → Actions:
| Secret | Description |
|---|---|
SSH_KEY |
Private SSH deploy key for the target server |
MAIN_LARAVEL_ENV |
Full contents of the production src/.env |
DEVELOP_LARAVEL_ENV |
Full contents of the staging src/.env |
| Workflow | Trigger | What It Does |
|---|---|---|
| Deploy | Push to main or develop |
SSH into the server, pull latest code, run migrations |
| PHP CS Fixer | Push / PR | Checks code style against Laravel conventions |
main → production
develop → staging / integration
feature/* → new features (merge into develop)
releases/* → release candidates (merge into main)
Pull requests should target develop. Only develop merges into main via a release branch.
Contributions are welcome! Here is how:
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-improvement - Commit your changes:
git commit -m "feat: add my improvement" - Push to your fork:
git push origin feature/my-improvement - Open a Pull Request targeting the
developbranch
Please keep PRs focused — one feature or fix per PR. For larger changes, open an issue first to discuss the approach.
This project is licensed under the GNU General Public License v3.0.