laravel/sail
Laravel Sail offers a Docker-powered local development environment for Laravel on macOS, Windows (WSL2), and Linux. With a simple CLI and no extra dependencies beyond Docker, it lets you spin up a full dev stack quickly—even without Docker experience.
Installation:
composer require laravel/sail --dev
sail install
This generates a docker-compose.yml (now compose.yaml) and .env file in your project root.
First Run:
sail up -d
Starts all services (MySQL, Redis, etc.) in detached mode.
Basic Commands:
sail artisan migrate # Run migrations inside containers
sail php artisan tinker # Access Tinker
sail npm run dev # Run npm scripts
Key Files:
docker-compose.yml (or compose.yaml): Defines services (PHP, MySQL, Redis, etc.)..env: Environment variables for containers (e.g., DB_HOST=mysql).sail: Alias script for Docker commands (auto-generated).Replace localhost in .env with service names (e.g., DB_HOST=mysql, REDIS_HOST=redis). Test with:
sail artisan serve
Access your app at http://localhost.
Artisan Commands:
Prefix any artisan command with sail:
sail artisan queue:work
sail artisan schedule:run
Database Management:
sail artisan migrate:fresh --seed
mysql service directly:
sail mysql
Node.js/Yarn:
sail npm install
sail npm run dev
sail yarn test
Custom Services:
Extend compose.yaml to add services (e.g., PostgreSQL, MongoDB):
services:
postgres:
image: 'postgres:18'
ports:
- '5432:5432'
environment:
POSTGRES_USER: sail
POSTGRES_PASSWORD: password
POSTGRES_DB: sail
Then update .env:
DB_CONNECTION=pgsql
DB_HOST=postgres
Volume Mounts: Bind local directories to containers for live reloading:
volumes:
- ./:/opt
Environment Variables:
Override defaults via .env or CLI:
sail --env=testing up
mailpit (SMTP) or laravel-echo (Pusher).compose.yaml:
services:
laravel.test:
build:
context: .
dockerfile: Dockerfile
Port Conflicts:
port is already allocated.ports in compose.yaml or stop conflicting services (sail down).Missing Dependencies:
command not found (e.g., node, composer).sail composer install).Permission Issues:
Permission denied when writing to volumes.docker group or use sudo (not recommended).Environment Variables Not Loading:
.env changes ignored.sail down && sail up) or use sail restart.Xdebug Not Working:
XDEBUG_MODE=debug is in .env and IDE is configured for laravel.test host.Windows (WSL2) Quirks:
sail --mac for macOS-like paths or ensure WSL2 is enabled./mnt/c/ instead of C:\.sail logs -f laravel.test # Follow logs for a service
sail logs mysql # Check MySQL logs
sail shell # Laravel container
sail mysql # MySQL container
sail artisan tinker # Run Tinker inside container
sail ps # List running containers
sail up --force-recreate # Rebuild containers
Custom PHP Extensions:
Extend the Dockerfile or use compose.yaml:
services:
laravel.test:
image: laravel/sail:8.2-apache
extra_hosts:
- "host.docker.internal:host-gateway"
For custom extensions, create a Dockerfile:
FROM laravel/sail:8.2-apache
RUN docker-php-ext-install swoole
Node Version:
Override Node.js version in compose.yaml:
services:
laravel.test:
environment:
NODE_VERSION: 20
AI Agent Variables: Forward host-specific env vars (e.g., for GitHub Copilot):
GITHUB_COPILOT_ENABLED=true
Podman Support:
Use SAIL_DOCKER_BINARY=podman in .env for Podman compatibility.
Custom Services:
Add new services to compose.yaml and update .env:
services:
typesense:
image: typesense/typesense:0.27.1
ports:
- "8108:8108"
TYPESENSE_HOST=typesense
Override Defaults:
Copy vendor/laravel/sail/stubs/ to your project and customize:
docker-compose.yml.stub → docker-compose.yml.env.stub → .envCI/CD Integration:
Use sail test or sail artisan test in GitHub Actions:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: docker-compose up -d
- run: sail artisan test
VS Code Dev Containers:
Use the devcontainer.json stub to enable full-featured containers in VS Code:
{
"name": "Laravel Sail",
"dockerComposeFile": "docker-compose.yml",
"service": "laravel.test",
"workspaceFolder": "/opt"
}
~/.bashrc or ~/.zshrc):
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
compose.yaml for large projects:
deploy:
resources:
limits:
cpus: '2'
memory: 4G
sail up service1 service2 to start specific services.sail/mysql, sail/postgres, etc., to version control for local backups.
How can I help you explore Laravel packages today?