BYTETOOLS

docker run to docker-compose Converter

Convert any docker run command into a docker-compose.yml file. Maps ports, volumes, environment, networks, restart policies and healthchecks to Compose YAML.

What is the docker run to docker-compose Converter?

Paste a docker run command — however long, with backslash line continuations and quoted values — and this tool rewrites it as a docker-compose.

  • Quote-aware tokeniser that handles multi-line commands pasted from a terminal
  • Maps 30+ flags including -p, -v, -e, --network, --restart, --cap-add and --health-cmd
  • Correct YAML quoting so port pairs and colon-bearing values survive intact
  • Declares named volumes and external networks automatically
  • Flags with no Compose equivalent are reported instead of silently dropped
  • 100% client-side — your command never leaves the browser

How to use the docker run to docker-compose Converter

  1. 1

    Paste your full docker run command into the box; trailing backslashes and quotes are handled.

  2. 2

    Choose whether to include the legacy version: key, which modern Compose ignores.

  3. 3

    Click Convert to Compose.

  4. 4

    Review any notes about flags that have no Compose equivalent, such as -d or --rm.

  5. 5

    Copy the YAML or download it as docker-compose.yml and run docker compose up -d.

About the docker run to docker-compose Converter

Paste a docker run command — however long, with backslash line continuations and quoted values — and this tool rewrites it as a docker-compose.yml service. A quote-aware tokeniser splits the command exactly as a shell would, then every flag is mapped onto its Compose equivalent.

Ports, volumes, environment variables, env files, networks, labels, capabilities, devices, DNS servers, the restart policy, working directory, user, entrypoint, healthcheck and resource limits are all translated. Named volumes and external networks are declared at the bottom of the file so it works the moment you save it.

Values are quoted correctly for YAML — port mappings especially, since a bare 8080:80 in a YAML list is parsed as a mapping rather than a string. Everything runs locally in your browser; no command is executed and nothing is uploaded.

Frequently asked questions

How do I convert docker run to docker-compose?

Paste the command and click Convert. Each flag is mapped to its Compose key — -p becomes ports, -v becomes volumes, -e becomes environment, --restart becomes restart — and the image becomes the service's image with any trailing arguments turned into command.

Why are my ports wrapped in quotes?

Because they have to be. In YAML an unquoted 8080:80 inside a list is read as a mapping, and values like 22:22 can be interpreted as a sexagesimal number under YAML 1.1. Quoting port mappings is the standard fix and is why the official Compose docs quote them too.

What happens to the -d and --rm flags?

They have no Compose equivalent and are reported as notes rather than translated. Detaching is a property of the command you run, so use docker compose up -d, and remove containers with docker compose down.

Do I still need the version key in docker-compose.yml?

No. The Compose Specification dropped it and modern versions of Docker Compose ignore it, often with a warning. It is off by default here, but you can switch it on if you are targeting an older tool that still expects it.

Does this handle named volumes?

Yes. When a volume's source is not a filesystem path — for example pgdata:/var/lib/postgresql/data — it is treated as a named volume and declared in the top-level volumes section so Compose will create it for you.

Is my docker command sent to a server?

No. The command is parsed and converted entirely in your browser, so it is safe to paste commands that contain environment variables, tokens or internal hostnames.

Related tools