Docker Run to Compose
Convert docker run commands into a docker-compose.yml (compose.yaml): ports, volumes, environment, networks, health checks, resource limits, GPUs and more.
services:
db:
image: postgres:17
container_name: db
restart: unless-stopped
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: app
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 10s
retries: 5
volumes:
pgdata:
Save it as compose.yaml and run docker compose up -d. Flags that only change how the CLI runs (like -d and --rm) aren't part of a Compose file.
About this tool
Paste one or more docker run commands and get a clean Compose file. The converter reads commands the way a shell does (quotes, escapes and line continuations from bash, PowerShell and cmd) and maps over 80 docker run options: ports, named volumes and bind mounts (with $(pwd) turned into relative paths), --mount, tmpfs, environment variables and env files, networks with aliases and fixed IPs, restart policies, health checks, logging, memory and CPU limits, ulimits, sysctls, capabilities, devices and GPUs. Several commands become several services, networks they share are declared once, and literal $ signs are escaped so Compose doesn't treat them as variables. Anything Compose can't express is listed as a warning.
How to convert docker run to Compose
Make a compose.yaml from docker run commands.
- 1
Paste the commands
Paste one or more docker run commands; multi-line commands with \ or ` are fine.
- 2
Check the warnings
Read any notes about options Compose can't express.
- 3
Save the file
Download compose.yaml and run docker compose up -d.