Stack
Used for the Compose project, the image name and the database name.
Services
How visitors reach it
Your files
Start it
How to use the Docker Compose generator
- Choose the app, the database and whether you want Redis. For Laravel, choose whether to run a queue worker and the scheduler as their own containers.
- Choose how visitors reach it: through Nginx already running on the server, through a Caddy container that gets HTTPS certificates by itself, or a published port for quick tests.
- Save each file in your project folder under the name shown, then run
docker compose up -d.
Passwords in the .env file are generated in your browser with its secure random number generator. Nothing is sent to Cloudhim. Keep .env out of Git.
What makes this compose file production-friendly
- Healthchecks with conditions. The app waits until the database actually accepts connections (
condition: service_healthy), not just until its container has started. That avoids the “connection refused” errors many stacks hit on the first boot; see SQLSTATE[HY000] [2002] Connection refused in Docker. - Restart policy. Every service uses
restart: unless-stopped, so it comes back after a crash or a server reboot. Our guide to healthchecks and restart policies explains the options. - Named volumes for data. Database, Redis and WordPress files live in named volumes that survive
docker compose downand image upgrades. - Nothing exposed by accident. Ports are bound to 127.0.0.1 by default and the database has no published port at all. Docker writes its own firewall rules, so a port published on all interfaces is reachable even when UFW says it’s blocked; see Docker bypasses UFW.
- Secrets in .env. Compose reads the
.envfile next tocompose.yamland fills in${DB_PASSWORD}and the other variables. For Laravel that’s the same.envthe app uses.
The Laravel stack
Laravel runs as PHP-FPM in its own container built from the generated Dockerfile, with Nginx in front of it serving public/. The queue worker and scheduler reuse the same image with a different command, so they always run the same code and PHP version. After a deploy, run php artisan queue:restart so the worker picks up the new code. If you’d rather run workers on the host instead of in containers, the Supervisor & systemd Generator writes the config.
Backups
Don’t back up a running database by copying its volume; the files can be mid-write. Dump it instead, for MySQL with docker compose exec -T db sh -c 'exec mysqldump -u root -p"$MYSQL_ROOT_PASSWORD" --all-databases' > backup.sql (MariaDB 11 calls the tool mariadb-dump and the variable MARIADB_ROOT_PASSWORD; PostgreSQL uses pg_dump), and copy the dump off the server. Our guide to automatic MySQL backups to Cloudflare R2 sets that up on a schedule.