Convert docker run to docker compose
Convert one or more docker run commands into a docker compose file. Handles -p, -v, --mount, -e, --env-file, --name, --restart, --network, -w, -u, --entrypoint, healthchecks, --gpus and the image's command, and explains what has no Compose equivalent.
🔒 Runs entirely in your browser. Nothing you paste is uploaded or sent to a server.
How flags map to Compose keys
| docker run | compose.yaml |
|---|---|
--name web |
container_name: web, and the service is named web |
-p 8080:80 |
ports: ["8080:80"] |
-v ./data:/data, -v pgdata:/data |
volumes:; named volumes are also declared at the top level |
--mount type=bind,… |
long-syntax volume (type, source, target, read_only) |
-e KEY=value, --env-file .env |
environment:, env_file: |
--network mynet |
networks: [mynet] + top-level external: true |
--network host |
network_mode: "host" |
--restart unless-stopped |
restart: unless-stopped |
-w, -u, --entrypoint |
working_dir, user, entrypoint |
| arguments after the image | command: [...] |
-it |
stdin_open: true, tty: true |
Gotchas the converter handles
- Always quote ports. YAML 1.1 reads
22:22as a base-60 number (1342), so the converter always writes ports as strings. $must be doubled. Compose substitutes${VAR}and$VARfrom your shell and.env, so a password likepa$wordmust be writtenpa$$word. The converter does this for you.restart: "no"needs quotes, because a barenois a boolean in YAML.$(pwd)becomes.. Relative paths in compose.yaml are relative to the file itself.--rmand-dare not file settings. Usedocker compose up -d, anddocker compose run --rm servicefor one-off tasks.- Named volumes get a project prefix.
pgdatabecomesmyproject_pgdata, so addexternal: trueto reuse data created bydocker run.
You don't need a top-level version: key any more (see the attribute version is obsolete). If docker compose up then fails with port is already allocated, the old docker run container is probably still running: docker rm -f <name> first.
Last updated 2026-11-20.