Skip to content

Menu

Docker Run to Compose

Convert docker run commands to docker-compose.yml

Runs entirely in your browserDevOpsFree, no sign-up
Loading tool

01What is Docker Run to Compose?

Self-hosting guides love a long docker run line. It works once, then you forget which flags you used. This converter turns that command into a Compose service you can keep in git. First it splits the command the way a POSIX shell does. Backslash line continuations are joined. Single quotes keep everything literal. Inside double quotes a backslash only escapes $, `, " and \. Both docker run and docker container run are accepted, with or without sudo. Short flags are expanded, so clusters like -dit, -dp 8080:80 and glued values like -p8080:80 work. Then each flag maps to the key the Compose Specification uses. -p becomes ports, -v becomes volumes, -e becomes environment, -w becomes working_dir, --memory becomes mem_limit, -i and -t become stdin_open and tty. It also covers --name, --restart, --cpus, --hostname, --cap-add, --cap-drop, --entrypoint, --label, --log-driver, --user, --dns, --add-host, --device, --tmpfs and a few more. The first word that isn't an option is the image. Everything after it becomes command as an exec-form array, so sh -c "..." keeps its grouping. A few details save you edits later. $(pwd), ${PWD} and $PWD in a volume become ".", which Compose resolves next to the compose file. Named volumes get a top-level volumes: entry. --network host, bridge or none becomes network_mode, and any other network is declared with external: true. A bare -e NAME is written as NAME: with no value, so Compose takes it from your shell. Literal $ signs are doubled to $$, as the Compose docs on interpolation require. Here's a worked example. Take sudo docker run -dp 5432:5432 -e POSTGRES_PASSWORD -v pgdata:/var/lib/postgresql/data --network backend --gpus all postgres:16. You get a service called postgres with the port, the volume, POSTGRES_PASSWORD: with no value and networks: backend. Top-level backend is marked external and pgdata is declared under volumes:. A comment at the top reads "# Not converted (add by hand if needed): --gpus all". That comment is the main limit. Flags with no mapping here, such as --gpus or --pids-limit, are listed rather than translated. -d and --rm are dropped on purpose, since docker compose up -d and docker compose run --rm cover them. An unknown long flag is assumed to take a value, which can swallow the image name in rare cases. Without --name, the service name comes from the image path minus its tag.

Self-hosters and backend developers who start containers with long docker run commands and want the same setup as a Compose file they can version. The tool runs entirely in your browser, so your data never leaves your device.

02How to use Docker Run to Compose

  1. Paste the full command into the Docker Run Command box. Multi-line commands with trailing backslashes are fine.
  2. Read the generated file in the docker-compose.yml panel. If something is wrong, such as a missing image, an error shows instead.
  3. Check the top of the output for a "# Not converted" comment and add those settings by hand.
  4. Click Copy Output and save the text as compose.yaml or docker-compose.yml.
  5. Click Reset to clear the input before converting the next command.

03Worked examples

Input: docker run -d --name web -p 8080:80 nginx:alpine
Result: services: web: image: "nginx:alpine" container_name: web ports: - "8080:80"
-d has no Compose key. You choose detached mode with docker compose up -d.
Input: docker run --rm -it -e NODE_ENV=production -v $(pwd):/app -w /app node:20 npm test
Result: services: node: image: "node:20" volumes: - ".:/app" environment: NODE_ENV: production working_dir: /app command: ["npm", "test"] stdin_open: true tty: true
$(pwd) becomes ".", and -i and -t map to stdin_open and tty. --rm is dropped.
Input: docker run -d -p 127.0.0.1:6379:6379 --restart=always redis:7
Result: services: redis: image: "redis:7" ports: - "127.0.0.1:6379:6379" restart: always
The bind address is kept, so Redis is still only reachable from the host.
Input: docker run -d --memory 512m --cpus 1.5 ghcr.io/acme/api:v2
Result: services: api: image: "ghcr.io/acme/api:v2" mem_limit: "512m" cpus: "1.5"
With no --name, the service is named after the last part of the image path, minus the tag.
Input: sudo docker run -dp 5432:5432 -e POSTGRES_PASSWORD -v pgdata:/var/lib/postgresql/data --network backend --gpus all postgres:16
Result: # Not converted (add by hand if needed): --gpus all services: postgres: image: "postgres:16" ports: - "5432:5432" volumes: - "pgdata:/var/lib/postgresql/data" environment: POSTGRES_PASSWORD: networks: - backend networks: backend: external: true volumes: pgdata:
The -dp cluster is expanded, the bare -e passes the value through from your shell, and --gpus is flagged.
Input: docker run alpine sh -c "echo \$HOME && sleep 1"
Result: services: alpine: image: alpine command: ["sh", "-c", "echo $$HOME && sleep 1"]
The escaped $ is doubled to $$ so Compose passes it to the container shell instead of interpolating it.

04Common use cases

  • Moving a Postgres or Redis container you started from a README into a compose file next to your app
  • Turning the long docker run line from a self-hosting guide into a file you can commit and diff
  • Recovering how a container was started from the ExecStart line of an old systemd unit
  • Building a multi-service stack by converting one docker run command at a time and pasting the services together
  • Checking which flags in a command have no Compose equivalent before you switch a server over
  • Fixing a command whose $ signs keep getting eaten by Compose interpolation

05Tips

  • Run docker compose config on the saved file. It prints the fully resolved YAML and complains about anything Compose doesn't accept.
  • container_name pins the container's name, which blocks docker compose up --scale for that service. Delete the line if you don't need a fixed name.
  • Networks other than host, bridge and none come out as external: true. Create them first with docker network create, or delete external to let Compose own them.
  • A -e value with a password ends up in plain text. Move it into an env_file that is in your .gitignore.
  • If a command uses a long boolean flag this tool doesn't know, write it as --flag=true. Otherwise it is assumed to take a value and may grab the next word, even the image.

06Related concepts

Docker Compose, Container orchestration, YAML, Named volumes, Bind mounts.

Frequently Asked Questions

What is Docker Run to Compose?

Docker Run to Compose is a free, browser-based developer tool on AIDToolStack. Convert docker run commands to docker-compose.yml It requires no installation or sign-up and works entirely in your browser.

Is Docker Run to Compose free to use?

Yes. No sign-up, no fees and no usage cap.

Does Docker Run to Compose store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe