Docker Compose setup
Goal
Give the project one command, docker compose up, that starts every service the app needs in a working order.
A good result starts cleanly from a fresh checkout, keeps data across restarts, and does not expose internal ports to the network by accident.
When to use
- The user wants a local dev stack with a database, cache, queue or mail catcher.
- An existing compose file starts services in the wrong order or loses data.
- Services fail with connection refused or name resolution errors.
- For the application image itself, use
use_skillwithdockerfilefirst.
Steps
- List what the app needs. Use
rgfor connection strings,process.envoros.environreads, and.env.example, and read the README withread_file. - Check for an existing
compose.yamlordocker-compose.ymlwithls. Edit it instead of adding a second file. - Run
run_commandwithdocker compose versionto confirm Compose v2 is installed. Check the live docs withread_urlbefore using any newer key you are unsure of. - Define one service per process. Pin image tags to a specific minor version instead of
latest, and look the current tags up on the registry page withread_urlrather than guessing. - Give every stateful service a named volume, and mount it at the data directory the image documents, not at a guessed path.
- Add a
healthcheckto each dependency (for examplepg_isreadyfor Postgres) and usedepends_onwithcondition: service_healthyin the app service. - Let services reach each other by service name on the default network. Replace
localhostin the app's connection strings with the service name. - Publish ports only for what the developer needs from the host. Bind them as
127.0.0.1:5432:5432so the database is not open to the LAN. - Move secrets and tunables to an
env_file, add the file to.gitignore, and commit an.env.examplewith placeholder values. - Run
docker compose configwithrun_commandto validate the merged file, thendocker compose up -danddocker compose psto see health states. - Check logs with
docker compose logs --tail 50 <service>for each service that is not healthy, and fix the cause rather than adding a restart policy. - Document the commands (up, down, reset data with
down -v) in the README withedit_file.
Gotchas
depends_onwithout a health condition only waits for the container to start, not for the database to accept connections.- Inside a container
localhostis the container itself. A connection string copied from a host-run setup breaks. - A bind mount over
node_modulesor a virtualenv hides what the image installed and causes missing-module errors. - Running
docker compose down -vdeletes named volumes. Never suggest it without saying the data is lost. - Init scripts in
/docker-entrypoint-initdb.drun only when the data directory is empty, so edits seem to be ignored on an existing volume. - A published port bound to
0.0.0.0can be reached from other machines, and Docker bypasses some host firewall rules.
Output
- The created or edited compose file path, with the services it defines.
- The exact commands to start, stop and reset the stack.
- Which ports are exposed on the host and why.
- Anything not verified because Docker was unavailable.
