Skip to content
TabBench

Docker Run to Compose

Convert docker run terminal commands into clean, readable docker-compose.yml files.

Runs in your browser. Nothing you add is uploaded.

What the Docker Run to Compose does

Paste a docker run command, even one split over several lines with backslashes, and get the equivalent service in a docker-compose.yml in the current Compose Specification format. Ports, volumes, environment variables and env files, restart policy, networks, memory and CPU limits, working directory, user, entrypoint, hostname, added capabilities, extra hosts and labels are all mapped. Arguments after the image become the service's command as a list, so quoted arguments like sh -c "a && b" survive intact, and any flag the converter does not map is listed under the output instead of being dropped silently.

How to convert docker run to Docker Compose

  1. Paste the command (with or without sudo docker run in front), or pick a preset: Nginx, PostgreSQL, Redis with limits, or a Node app with networks.
  2. Read the generated YAML. The service is named after --name, or after the image when there is no name.
  3. Check the warning under the output for flags that were not converted, such as --gpus, and add those to the file yourself.
  4. Copy the YAML or download docker-compose.yml, then run docker compose up -d in the same folder.

The Docker Run to Compose runs entirely in your browser — nothing you enter is uploaded, stored, or logged.

When to use it

Turning a one-off command into a file

A docker run line with a dozen flags lives in shell history until it is lost. As a compose file it can be committed, reviewed and re-run with docker compose up -d, and changing one port or variable no longer means retyping the whole command.

Starting point for a self-hosted app

Many projects document installation as a single docker run command. Converting it gives you a compose file to build on, adding a database service, a reverse proxy or a backup container next to it.

Seeing what a command really grants

Laid out as named keys (privileged: true, network_mode: host, cap_add), it is obvious when a command copied from a forum gives the container more access than the app needs.

Good to know

  • --network host, none or bridge become network_mode. Any other network name becomes an external network, which you are expected to have created with docker network create.
  • Bind mounts (./data:/data, /srv/app:/app) stay as paths. A name before the colon (pgdata:/var/lib/postgresql/data) is a named volume and is declared at the bottom of the file.
  • -m and --cpus become deploy.resources.limits, which docker compose up applies in current Compose versions.
  • container_name is only added when the command used --name. Leaving it out lets Compose name containers itself, which you need if you ever scale the service.
  • -d, -it and --rm have no compose equivalent and are dropped: docker compose up -d runs detached, and docker compose run --rm gives a throwaway container.

Frequently asked questions

Why should I convert docker run into Docker Compose?

Docker Compose files are version-controlled, declarative, and repeatable. Instead of remembering complex 10-line CLI commands, you can manage multi-container setups with a single 'docker compose up -d'.

Does this handle named volumes and bind mounts?

Yes. It automatically differentiates between local bind mounts (e.g., ./data:/data) and named volumes, declaring named volumes at the bottom of the Compose file.

Does this support multi-line docker run commands with backslashes?

Yes. Backslash line continuations are joined before the flags are read, so a command copied from documentation works as pasted.

What version of Docker Compose is generated?

The Compose Specification used by Docker Compose v2 (the docker compose command). The old top-level version: key is not written; current Compose ignores it and prints a warning when it is present.

Why is a flag listed as not converted?

docker run has many flags and only the common ones are mapped. Others, such as --gpus, --device, --log-driver or --ulimit, have compose equivalents with a different shape (GPU access, for example, goes under deploy.resources.reservations.devices), so they are listed for you to add rather than guessed.

Page last updated . Found a wrong result or a mistake on this page? Let us know.