Scaffolds production-grade Docker setup for PHP/Laravel applications. Multi-stage builds, php-fpm + nginx, dev/test/prod targets. Trigger: "docker", "containerize", "Dockerfile", "docker-compose".
php:8.4-fpm-alpine. Always alpine. Fewer CVEs, smaller surface.base, dev, test, prod.dev stage adds xdebug, pcov. Mounts source via volume. Never copies source.test stage copies source + dev dependencies. CMD runs phpunit.prod stage copies source + no-dev dependencies. Opcache ON. Runs as non-root.prod stage with a different CMD.Always copy dependency files BEFORE source code:
COPY composer.json composer.lock ./
RUN composer install --no-scripts --no-autoloader
COPY . .
RUN composer dump-autoload --optimize
This caches composer install unless dependencies actually change.
www-data (USER directive before CMD).HEALTHCHECK CMD php-fpm -t || exit 1HEALTHCHECK CMD curl -sf http://localhost/health || exit 1/up route (since Laravel 11).docker compose up → development (volumes, xdebug, local DB)docker compose -f docker-compose.yml -f docker-compose.prod.yml up → productiondocker compose -f docker-compose.yml -f docker-compose.test.yml run --rm test → CIAlways exclude: .git, vendor/, node_modules/, .env, tests/, .claude/,
specs/, checkpoints/, docker-compose*.yml.
Check project for Laravel/Symfony/vanilla. Ask only what can't be inferred: database choice, Redis needed, Node.js asset building, extra PHP extensions.
Adapt the templates in this skill's templates/ directory. Generate:
docker/
php/Dockerfile
php/php-dev.ini
php/php-prod.ini
nginx/Dockerfile
nginx/default.conf
docker-compose.yml
docker-compose.prod.yml
docker-compose.test.yml
.dockerignore
After generating, briefly explain the stage strategy and how docker-compose targets work. Don't over-explain — the developer can read the files.
templates/Dockerfile.php for the multi-stage PHP build.templates/Dockerfile.nginx for the nginx + asset build.templates/default.conf for the FastCGI proxy config.templates/php-dev.ini for dev PHP settings (xdebug, permissive limits).templates/php-prod.ini for production PHP settings (opcache, JIT, hardening).templates/docker-compose.yml for the dev environment.templates/docker-compose.prod.yml for production overrides.templates/docker-compose.test.yml for CI overrides.