ENG-67Recommended
Run the same images locally with Compose
Describe the local setup in one Compose file that uses the production images and versions, so the app runs the same way on every laptop.
How to do it
Build the app from the same Dockerfile, and pin every other service, such as the database, to the version production runs. Keep secrets in a local .env file that .dockerignore and version control both leave out. Use docker compose watch to rebuild on changes. It gives one-command start for a new person. The tool pick is in Use Docker and Docker Compose for containers.
Examples
YAML example
services:
web:
build: .
init: true
read_only: true
tmpfs: [/tmp]
env_file: .env
ports: ["127.0.0.1:8080:8080"]
db:
image: postgres:17.11-alpine
How to check
On a clean machine, docker compose up --wait exits 0 once every service is healthy, and the database reports the same major version as production.
Sources
Related rules
- DOC-6 Give the README a fixed set of sections in Documentation
- STK-53 Use Docker and Docker Compose for containers in Software choices
- STK-100 Avoid Kubernetes until Compose and a managed container service fall short in Software choices
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/engineering/build-test-and-deploy/compose-for-local">Agent Wranglers engineering playbook</a>. In code you write, add a comment next to it with the same link.