Skip to content

Docker Run to Docker Compose Converter

Convert docker run commands to compose.yaml, and back. Runs in your browser.

Loading tool…

About this docker run to docker compose converter

This converter turns docker run commands into a compose.yaml file, and turns a Compose file back into docker run commands. It is for anyone who started a container from a README one-liner and now wants it in a file they can commit, restart and share.

Paste one command or several. Backslash line breaks, quotes, paths with spaces and a leading sudo are all fine. Each command becomes a service. Ports, volumes, environment variables, restart policy, networks, healthchecks, resource limits, GPUs, capabilities and dozens of other flags are mapped to their Compose keys. Anything without a Compose equivalent, such as --rm, gets a note that explains why.

Going the other way, each service becomes a docker run command, with the networks and named volumes it needs created first. The conversion runs in your browser, so passwords in environment variables stay on your machine.

Features

  • Both directions

    docker run to Compose and Compose to docker run on one page. Switching directions carries the output across, so you can check a round trip.

  • Several commands at once

    A database, an app and a cache pasted together become three services in one file. Named volumes get a top-level volumes: block.

  • A real shell parser

    Single and double quotes, $'…' strings, backslash continuations and Windows caret continuations are read the way a shell would, so -v "/my data:/data" keeps its space.

  • Wide flag coverage

    -p, -v, --mount, -e, --env-file, --restart, --network with aliases and fixed IPs, healthcheck flags, --memory, --cpus, --gpus, --cap-add, --device, --ulimit, --sysctl, logging options and more.

  • Notes you can act on

    Flags with no Compose key, ports ignored by network_mode: host, container_name blocking scaling, and depends_on not waiting for health are all called out.

  • Clean YAML

    No obsolete version: line, values quoted only where YAML could misread them, and a choice of 2 or 4 space indent. Edited it by hand later? Validate it in the YAML formatter.

How to use the docker run to docker compose converter

  1. 1Choose docker run → Compose or Compose → docker run.
  2. 2Paste your commands or your compose.yaml.
  3. 3Read the notes on flags that need a manual check, then copy or download.

When to use it

  • Moving a self-hosted app into Compose

    Most project READMEs give a docker run line. Convert it, save compose.yaml and from then on it is docker compose up -d.

  • Combining containers that talk to each other

    Paste the app and its database commands together. In Compose they share a network and reach each other by service name, so --link is no longer needed.

  • Debugging one service by hand

    Turn a Compose service into a docker run command to start it alone with extra flags, or with -it and a shell as the command.

  • Documenting a setup

    Give users both forms in your docs. Compose for people who use it, a single docker run for a quick try.

How does a docker run command map to Compose?

docker run takes options, then the image, then an optional command. In Compose, the image becomes image:, the command after it becomes command:, and most options become keys of the same service. A few common ones:

  • -p 127.0.0.1:8080:80 becomes ports: - "127.0.0.1:8080:80". Without an IP, the port is published on every interface.
  • -v pgdata:/var/lib/postgresql/data becomes a volumes: entry plus pgdata: under the top-level volumes key.
  • -e KEY=value becomes environment: KEY: value. -e KEY alone copies the variable from your shell, written as KEY with no value.
  • --restart unless-stopped becomes restart: unless-stopped, with the same four policies.
  • --health-cmd and the other --health flags become a healthcheck: block with test: ["CMD-SHELL", …].
  • --gpus all becomes a deploy.resources.reservations.devices entry with the nvidia driver and the gpu capability.

Which docker run flags have no Compose equivalent?

-d is not needed, because docker compose up -d detaches. --rm has no key: docker compose down removes containers, and docker compose run --rm does the same for one-off runs. -P publishes every exposed port to a random host port, which Compose cannot express, so list the ports instead.

A few flags change meaning. --network with a network you created yourself is marked external: true, because Compose would otherwise create its own copy with a project prefix. --name becomes container_name, which works but stops docker compose up --scale from running more than one copy.

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

No. The Compose Specification says the top-level version property is obsolete and kept only for backward compatibility. Docker Compose v2 ignores it and prints a warning. Files should start with services:, which is what this tool writes.

The file name changed too. compose.yaml is the preferred name today, and docker-compose.yml still works.

Converting Compose back to docker run

Each service becomes one command, with options before the image and the command after it. Named volumes and non-external networks get docker volume create and docker network create lines first, because docker run will not create a network for you.

Some Compose ideas do not exist for a single container. depends_on only sets start order, replicas means running the command several times, and build: needs a docker build first. Each case gets a note. ${VAR} placeholders are left as they are; Compose fills them from .env, while a shell needs them exported.

Why use Mavros

 MavrosTypical upload sites
Directionsrun to Compose and Compose to runOne direction per site
Multi-line commandsBackslash and caret continuations parsedOften fail on line breaks
Paths with spacesKept intact through quotingSplit into broken entries
Unsupported flagsListed with the reasonDropped silently
OutputNo version: line, safe quotingAdds an obsolete version: "3"

Tips

  • Quote port mappings in YAML. "8080:80" is safe, while some older YAML parsers read unquoted 22:22 as a base-60 number. This tool quotes them for you.
  • Put secrets in an env_file instead of the Compose file you commit. --env-file maps to env_file: directly.
  • Healthchecks pair well with depends_on: condition: service_healthy, so the app waits until the database answers.
  • Writing a scheduled job inside a container? Check the timing with the cron expression parser.
  • Volume files owned by the wrong user? Work out the mode bits with the chmod calculator.

Questions

How do I convert a docker run command to docker compose?

Paste the command and keep docker run → Compose selected. Copy the YAML into compose.yaml next to your project and start it with docker compose up -d.

Can I convert several docker run commands into one file?

Yes. Paste them one after another. Each becomes a service, named after --name or the image, and they share the default Compose network.

How do I turn a compose file into docker run?

Choose Compose → docker run and paste the YAML. You get one command per service, plus the docker network create and docker volume create lines it needs.

What is the Compose equivalent of --rm?

There isn't one for docker compose up. docker compose down removes the containers when you are done, and docker compose run --rm SERVICE removes a one-off container.

How do I write -p 127.0.0.1:8080:80 in Compose?

Use ports: - "127.0.0.1:8080:80". The IP limits the port to localhost, so other machines cannot reach it.

Should I use environment or env_file?

Use environment for a few non-secret values and env_file for secrets or long lists. When both set the same variable, the value under environment wins.

How is --gpus all written in Compose?

Under deploy.resources.reservations.devices, with driver: nvidia, count: all and capabilities: [gpu]. This tool writes that block for you.

Is my command sent to a server?

No. Parsing and conversion run in your browser, so passwords in -e values never leave your machine.