Skip to content

docker run to Compose

Turns a docker run command line into a compose service definition, and converts back the other way.

Converts a `docker run` command line into the `compose.yaml` service it corresponds to. The command is split with real shell quoting rules, so an entrypoint written as `sh -c "…"` survives with its spaces and quotes intact.

🔒 Runs entirely in your browserdockercomposeconvertdevops

docker run command

compose.yaml

Notes

  • -d only affects the docker run invocation itself; Compose has no equivalent, so it was dropped.
The command is split with real shell quoting rules, so an entrypoint like sh -c "…" survives with its spaces. Flags without a Compose equivalent (--rm, -d) are dropped with a note — Compose decides lifecycle itself — and unknown flags are named, never silently eaten. Ports are quoted in the output because YAML 1.1 would otherwise read 8080:80 as a base-60 number.

How to use it

  1. Paste the command

    Line continuations, quoted values and a trailing command after the image are all handled. Nothing is executed — this is text in, text out.

  2. Read the notes under the output

    Flags with no Compose equivalent are listed rather than dropped silently, and an unknown flag is named. That list is the part worth checking before you commit the file.

  3. Copy it into your compose file

    The output is one service. Put it under `services:` alongside whatever else you have, and give it the name you want if the command had no `--name`.

Common questions

Why are the ports quoted?

Because YAML 1.1 reads `8080:80` as a base-60 number — the sexagesimal syntax nobody wanted and every YAML parser inherited. Quoting is what keeps it a port mapping. This is the classic Compose foot-gun.

What happened to `--rm` and `-d`?

Dropped with a note, because Compose owns lifecycle. `docker compose up` is the detached/attached decision and `docker compose down` removes containers, so those flags have no service-level equivalent to translate into.

Does it write a whole compose file?

It writes the service. Networks, volumes at the top level, and a `version:` key (which modern Compose no longer wants) are yours to add — and mostly you should not need them.

Feed it from

Next

These accept what this tool produces, so the result can go straight in.