Dev tools

docker run → compose

Turn a `docker run` command into a docker-compose.yml service. Covers -p/-v/-e/--name/--network/--restart/-w/--entrypoint plus image+command; anything else is kept as a trailing comment instead of being silently dropped. Runs on your device.

Runs on your device. The file is never uploaded.

docker run to compose rewrites a docker run command as a docker-compose.yml service, starting at services with no version key. Eight flags translate: --name, --network, --restart, --entrypoint, --workdir, and -p, -v and -e become ports, volumes and environment. An unknown flag lands in a trailing # not translated comment, and the token after it is taken for the image.

Options

Questions

Which docker run flags are translated?

Eight, in both their short and long spellings where they have one. -p and --publish become ports, -v and --volume become volumes, -e and --env become environment, --name names the service, and --network, --restart, -w or --workdir and --entrypoint map to networks, restart, working_dir and entrypoint. The trailing image becomes image, and whatever follows it becomes a command array.

What happens to flags it does not know?

They are kept as a comment at the end of the output, starting "# not translated", rather than being dropped without trace. Flags that only matter at run time and have no place in a service definition are skipped silently: -d, --detach, -i, -t, -it and --rm. Everything else you passed is either translated or visible in that comment.

Why did my image name come out wrong?

Most likely an unknown flag that takes a separate value. The parser records the flag itself as untranslated and then treats the next token as the image, because the first non-flag token is taken to be the image. Write such flags in the --flag=value form and the whole thing stays one token and lands in the comment instead.

How is the service named?

From --name when you give one. Otherwise it comes from the image with everything from the first colon or slash removed, so nginx:latest becomes nginx. A registry-qualified image such as ghcr.io/acme/api therefore becomes ghcr.io, which is rarely what you want, so pass --name for those.

Does the output include a version key?

No. The file starts at services, since modern compose no longer needs a version. A --network value produces both a networks list on the service and a top-level networks block marking that network external: true, on the reasoning that docker run required it to exist already.

Why does it say no image found?

Because it reached the end of the command without meeting a non-flag token. That happens if you paste flags only, or if the last flag swallowed the image as its value. The leading docker and run words are optional, so a full command parses, and so do the flags plus the image on their own, and quoted arguments in single or double quotes are handled.

Related Dev tools