Docker Run to Compose
Turn a docker run command into a compose service.
What you paste
Parsed in your browser — never uploadedHow this reads your output
The command is tokenised with quoting respected, then each flag is mapped to its compose key. Ports, volumes and environment variables are collected into lists, and anything after the image name becomes the command. Flags with no equivalent are listed rather than silently dropped, because a rule you asked for and did not get is the failure that matters when the container comes up missing something.
What the results mean
- Flags not converted
- Options with no direct compose equivalent. Some map to a differently named key and some genuinely have no counterpart, so check each one.
- Quoted ports
- Port mappings are quoted deliberately. Unquoted, some YAML parsers read 8080:80 as a sexagesimal number and produce a port nobody intended.
- Possible secrets
- Environment variables whose names suggest a credential. A compose file usually gets committed, and a password in git history survives its removal.
Common problems and fixes
- A relative volume path resolves differently under compose
- Bind mount paths in compose resolve relative to the compose file location, not to the directory you run the command from. Moving a run command into a compose file in a different directory silently changes what gets mounted. Use paths relative to the compose file, and prefer named volumes for anything that is not source code.
- The container exits immediately under compose
- The detach flag has no compose equivalent because compose manages that itself, and an interactive container without a terminal exits at once. If the image expects a terminal, set tty and stdin_open. If it runs a foreground process, check the command was carried over correctly, since arguments after the image name are easy to lose.
Frequently asked questions
Why move to compose at all?
Because a one-off command lives in someone command history and a compose file lives in the repository. It documents what the container needs, survives the person who wrote it, and makes the configuration reviewable. Once more than one container is involved, it also handles the network between them.
Is it docker-compose or docker compose?
The hyphenated version is the original Python tool, now superseded. Current Docker ships compose as a subcommand of the docker command itself, written in Go. The file format is the same, and the version key at the top is obsolete in the current specification.
What about secrets in environment variables?
Move them out of the file. An env_file that is git-ignored is the simple approach; compose secrets are better, since they mount as files rather than sitting in the environment where any process in the container can read them and any crash dump can capture them.
Put this on your own site
Free to embed, no attribution required beyond the source link the frame carries itself. It runs entirely in your visitor's browser, sets no cookies and loads no third-party script.
<iframe src="https://runthetests.com/embed/docker-run-to-compose/" width="100%" height="720" style="border:1px solid #e5e5e5;border-radius:8px" title="Docker Run to Compose" loading="lazy"></iframe>
Preview it at https://runthetests.com/embed/docker-run-to-compose/. Embedded pages are marked noindex, so yours stays the canonical copy — not this one.