BrowserTools
Home / Converters / Docker Run to Compose

Docker Run to Compose

Turn a docker run command into a ready-to-use docker-compose.yml file.

Loading Docker Run to Compose… If nothing happens, please enable JavaScript.

Most projects start with a single docker run line copied from a README, and end up as a wall of flags nobody wants to retype. Paste that command here and this tool rewrites it as a docker-compose.yml file, mapping every option it recognises to the matching Compose key: -p becomes ports, -v becomes volumes, -e becomes environment, --restart becomes restart, and so on for roughly seventy flags including healthchecks, resource limits, logging drivers, capabilities, ulimits and GPU reservations.

Frequently asked questions

Is my docker run command sent to a server?
No. The parser and the YAML writer are plain JavaScript running in your browser, and the page makes no network request while converting. Commands often contain passwords, tokens or private registry names, so this matters: you can paste a production command and nothing is uploaded, logged or stored.
Which docker run options are supported?
About seventy of them, including the common ones (--name, -p, -v, -e, --restart, --network, -w, -u, --entrypoint, --hostname), the resource limits (--memory, --cpus, --pids-limit, --shm-size, --ulimit), the security options (--cap-add, --cap-drop, --security-opt, --privileged, --read-only), the healthcheck family, --log-driver with --log-opt, --mount, --tmpfs, --sysctl, --device and --gpus. The full list is in the flag reference table on the page, and anything unrecognised is reported under Notes rather than dropped in silence.
Why is -d missing from the generated file?
Detaching is not a property of a service, it is how you start it. Compose runs everything in the background when you use docker compose up -d, so the flag has no key in the file. The same applies to --rm, which corresponds to docker compose down, and to attach-time options such as -a and --detach-keys.
Do I need the version key at the top of the file?
No, and that is why it is off by default. The Compose Specification dropped it, and recent versions of Docker Compose print a warning when they find it. Turn the option on only if you still run the old Python docker-compose v1, which does expect a version field.
What happens to named volumes and networks?
A volume mount whose source is not a path, such as -v pgdata:/var/lib/postgresql/data, is a named volume, so pgdata is added to the top-level volumes section. Named networks passed with --network are added to the top-level networks section marked external, because the assumption is that the network already exists from your docker network create. Remove external: true if you would rather let Compose create it as part of the project.
Can I convert more than one container at once?
Yes. Paste several docker run commands, one per line or chained with && or ;, and each becomes a service. The service name comes from --name when present, otherwise from the image name, and duplicates get a numeric suffix. This is the quickest way to turn a run script for an application and its database into a single Compose file.
Why are port mappings written in quotes?
Because YAML 1.1 reads a bare 22:22 as a sexagesimal number, which is the classic Compose beginner trap. Quoting the value keeps it a string and keeps the mapping intact. Other values are only quoted when they need it, so the output stays readable.
Does it understand --mount and healthchecks?
Yes. A --mount specification is rewritten in the long volume syntax with type, source, target and read_only, which is what Compose expects for bind mounts and tmpfs mounts. The --health-cmd, --health-interval, --health-timeout, --health-retries and --health-start-period flags are collected into a healthcheck block, with the command wrapped as CMD-SHELL unless it already starts with CMD.
How do I run the file once it is generated?
Save it as docker-compose.yml (the Download button does that for you), open a terminal in the same folder and run docker compose up -d. Check it first with docker compose config, which validates the file and prints it back with everything resolved. Review the Notes section on this page before running anything in production, since a few flags have no equivalent and may need a manual decision.

About Docker Run to Compose

The converter reads the command the way a shell does. Backslash line continuations, single and double quotes, attached short flags such as -p8080:80, clustered flags such as -itd, and the --flag=value form are all handled, so you can paste a command straight out of documentation without cleaning it up first. Paste several commands, one per line or joined with &&, and each one becomes its own service in the same file. Named volumes and named networks used by those services are collected and declared in the top-level volumes and networks sections, and ports are quoted so that a value like 22:22 is not read as a sexagesimal number by the YAML parser.

Flags that only make sense while a container is being launched have no place in a Compose file, and the tool says so instead of silently dropping them: -d is replaced by docker compose up -d, --rm by docker compose down, and options like --cidfile or --detach-keys are listed under Notes with a short explanation. Everything runs in your browser with no server call and no external library, so commands that contain passwords, registry hostnames or internal image names never leave the page. Copy the result or download it as docker-compose.yml and run docker compose up -d in the same folder.

Compose started life as Fig

Before Docker Compose existed there was Fig, a small Python tool released in 2013 by Orchard Laboratories. Fig introduced the idea that a multi-container application should be described in one YAML file and started with a single command, at a time when the usual approach was a shell script full of docker run lines. Docker acquired Orchard in 2014 and Fig became docker-compose the following year, keeping the file format almost unchanged.

The file format then went through a decade of churn. Version 1 had no top-level keys at all, version 2 added services, volumes and networks, and version 3 was shaped by Docker Swarm, which is why keys like deploy still appear in files that will never touch a swarm. The numbering finally ended with the Compose Specification, which merged the version 2 and 3 branches and made the version field obsolete.

The rewrite from Python to Go in Compose V2 also changed how you invoke it: docker-compose with a hyphen became docker compose as a subcommand of the Docker CLI. The old standalone binary reached end of life in July 2023, so if a tutorial still tells you to add version: '3.8' at the top of the file, it was written for a tool that Docker no longer ships.

Support