A docker-compose.yml builder that turns a list of services — each with an image, ports, environment variables, volumes, and dependencies — into a valid Compose file complete with a top-level volumes block and a shared bridge network. It is built for developers spinning up a multi-container stack without hand-writing YAML and worrying about indentation.
How it works
Each service you add becomes one entry under the top-level services: key. The builder
emits the image, a sensible restart: unless-stopped, a quoted list of ports, an
environment map, a volumes list, and a depends_on list. Every service is attached to
a single declared appnet bridge network so containers can resolve one another by service
name.
Volume mounts are inspected: a source like db-data:/var/lib/postgresql/data is recognised
as a named volume and collected into the top-level volumes: block, while a source like
./src:/app is treated as a bind mount and left inline. This keeps the generated file
valid — named volumes must be declared, bind mounts must not.
Tips and notes
depends_ononly orders startup. For databases, add ahealthcheckto the db service and depend on it withcondition: service_healthyso your app does not connect before Postgres is accepting queries.- Inside the network, use the service name as the hostname. An
apiconnecting to adbservice should usedb:5432, notlocalhost. - Keep secrets out of the committed file — point sensitive services at an
env_fileor use shell-substituted variables likePOSTGRES_PASSWORD=${DB_PASSWORD}. - Run
docker compose configafter pasting the file to have Docker validate and normalise it before you bring the stack up.