Docker Run to Compose
Turn a docker run command into a compose.yaml service, with ports and environment values quoted so YAML can't retype them.
Local workspace
Named projects in IndexedDB · Local only — never synced to our servers. Worksp…
Batch workspace
Format multiple files locally in one run.
A docker run command grows one flag at a time until nobody remembers what it does, and moving it into Compose by hand is where subtle bugs appear: an unquoted 22:22 becomes the number 1342 under a YAML 1.1 parser, and an unquoted true becomes a boolean Compose refuses. This converter parses the command the way a shell does, so quoted arguments and backslash line continuations survive, then writes the YAML itself with every port, volume, and environment value quoted. Flags that only make sense for a single run, such as --rm, are listed in a comment instead of vanishing.
Common errors and fixes
services.web.ports contains an invalid type, it should be a string
An unquoted port mapping such as 22:22 was read as a number. Keep the quotes this converter adds around every port.
services.web.environment.DEBUG must be a string
Compose rejects bare booleans and numbers in environment. Keep values quoted, as the generated file does.
docker: invalid reference format
The command isn't a valid docker run: usually the image name is missing or a flag swallowed it. Check that the image comes after all flags.
The --rm flag was dropped
Compose has no per-service equivalent. Use docker compose run --rm service for one-off containers that clean up after themselves.
Options
| Option | Description |
|---|---|
| Service name | Leave empty to use the container name, or the image name when there isn't one. |
FAQ
Which docker run flags are converted?
The ones with a direct Compose key: --name, -p, -e, --env-file, -v, --restart, --network, -w, -u, --entrypoint, -i and -t, --hostname, --label, --add-host, --cap-add and --cap-drop, --device, --dns, and resource flags such as --memory. Anything without an equivalent is listed in a comment rather than dropped silently.
Why are ports and environment values quoted?
Because YAML 1.1 parsers read 22:22 as the number 1342 and true as a boolean. Quoting keeps them the strings Docker expects, which is the single most common way a hand-written compose file breaks.
What has no Compose equivalent?
--rm and --detach are choices you make when running, not part of the service: use docker compose run --rm and docker compose up -d. --gpus maps to a deploy block whose shape depends on your Compose version.
How do I run the result?
Save it as compose.yaml next to your project and run docker compose up. The modern format has no version key, which Compose v2 ignores anyway.
Can I convert several containers into one file?
Convert each docker run command separately, then paste the services under a single services: key. Names must be unique, so rename the second service if both came from the same image.