laravel/sail
Docker-based local dev environment for Laravel on macOS, Windows (WSL2), and Linux. Sail provides ready-to-use containers and a simple CLI so you can start developing without installing extra tools beyond Docker, even with no 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 (PHP, MySQL, Redis, etc.) in detached mode.
Access Services:
http://localhostsail mysqlsail artisan [command]Key Files:
docker-compose.yml (or compose.yaml): Defines services and configurations..env: Environment variables for Sail (e.g., SAIL_8000=true to expose port 8000).Replace php artisan serve with:
sail artisan serve
Sail handles:
Service Management:
sail up # Start all services
sail down # Stop and remove containers
sail ps # List running containers
sail logs # View logs
Customizing Services:
Extend compose.yaml to add services (e.g., RabbitMQ, MongoDB):
services:
rabbitmq:
image: rabbitmq:3.12
ports:
- "5672:5672"
Then run:
sail up -d rabbitmq
Environment-Specific Configs:
Use .env variables to toggle services:
SAIL_MYSQL_PORT=3306
SAIL_POSTGRES_PORT=5432
SAIL_XDEBUG=true
Artisan & CLI: Run Laravel commands inside containers:
sail artisan migrate
sail npm run dev
Volume Mounts: Bind host directories to containers for live reloading:
volumes:
- ./:/var/www/html
SAIL_XDEBUG=true and configure your IDE (e.g., VSCode) to use sail as the Docker host.compose.yaml for email testing:
mailpit:
image: axllent/mailpit
ports:
- "8025:8025"
sail test with Pest 4 support (v1.45.0+).devcontainer.json stub for IDE integration.Port Conflicts:
.env (e.g., SAIL_8000=true) don’t clash with host services.sail down and adjust .env or compose.yaml.Volume Permissions:
chmod -R 775 storage bootstrap/cache on the host.Docker Desktop Quirks:
PHP Extensions:
pdo_pgsql) require custom Dockerfiles.compose.yaml:
php:
build:
context: .
dockerfile: Dockerfile
Health Checks:
.env variables (e.g., DB_DATABASE) are misconfigured..env and restart with sail up -d --build.Logs:
sail logs -f php # Follow PHP container logs
sail logs mysql # Check MySQL issues
Shell Access:
sail shell # Bash into the PHP container
sail mysql # MySQL CLI
Common Errors:
sail ps to verify containers are up.sail up output for conflicts.SAIL_XDEBUG=true and IDE is configured for Docker.Custom Dockerfiles:
Override the PHP service in compose.yaml:
php:
build:
context: .
dockerfile: Dockerfile.custom
Example Dockerfile.custom:
FROM sail-php82/app AS builder
RUN apt-get update && apt-get install -y libpq-dev
Environment Variables:
Use .env or pass directly:
sail up -d --build --env MY_CUSTOM_VAR=value
Service Dependencies:
Add depends_on to compose.yaml:
redis:
depends_on:
- php
CI/CD:
Use sail test in GitHub Actions:
- name: Run tests
run: sail test
compose.yaml for memory/CPU:
deploy:
resources:
limits:
cpus: '1'
memory: 2G
sail-mysql) to avoid data loss on sail down.SAIL_DOCKER_BINARY=podman in .env for Podman users.How can I help you explore Laravel packages today?