Docker Run to Compose
Paste one or more docker run commands and get a docker compose file with ports, volumes, environment, networks, health checks and restart policies.
How to turn docker run into compose
Paste the commands
Paste one or more docker run commands, with or without line continuations.
Check the notes
Flags with no Compose equivalent, such as --rm, are listed.
Save compose.yaml
Download the file and start it with docker compose up -d.
Worked example
This is what Docker Run to Compose gives for its own sample values. Open the tool above and change anything to try your own.
docker run commands (one or more)
docker run -d --name db \ -e POSTGRES_PASSWORD=change-me -e POSTGRES_DB=app \ -v pgdata:/var/lib/postgresql/data \ --restart unless-stopped postgres:16 docker run -d --name web -p 8080:3000 \ -e DATABASE_URL=postgres://postgres:change-me@db:5432/app \ --health-cmd "curl -f http://localhost:3000/health || exit 1" --health-interval 30s \ --restart unless-stopped ghcr.io/acme/web:2.3.1
compose.yaml
services:
db:
image: postgres:16
container_name: db
environment:
POSTGRES_PASSWORD: change-me
POSTGRES_DB: app
volumes:
- pgdata:/var/lib/postgresql/data
restart: unless-stopped
web:
image: ghcr.io/acme/web:2.3.1
container_name: web
ports:
...When to use Docker Run to Compose
A project's README gives docker run commands and you want a Compose file you can start and stop with one command.
Several containers you run by hand need to become one stack that can be kept in version control.
Tips for a better Docker Run to Compose result
Paste all related commands together so the services share one file, and they can reach each other by service name.
Move secrets such as POSTGRES_PASSWORD out of the file into an .env file once the conversion is done.
Docker Run to Compose: limits and what to check
Flags the converter does not know are listed in the notes rather than guessed, so read the notes before deploying.
Networks are marked external because docker run expects them to exist, so create them first or remove that line.
About Docker Run to Compose
Turn the docker run commands from a README or your shell history into a Compose file you can keep in version control. Ports, volumes and mounts, environment variables, labels, networks, restart policies, health checks, resources, capabilities, logging and the command after the image are all carried across.
FAQs
What happens to named volumes and networks?
Named volumes are declared at the bottom for Compose to create. Networks are marked external, because docker run expects them to exist already.
Can I paste commands with backslashes?
Yes. Line continuations with \, ^ (Windows) and ` (PowerShell) are joined first.
Why is --rm not converted?
Compose manages container lifetimes itself: docker compose down removes the containers.