Docker Run to Docker Compose Converter

Paste a docker run command and get a docker-compose.yml service you can edit, copy or download. Everything happens in your browser; nothing is uploaded.

Updated November 19, 2026

docker run command

docker-compose.yml

You can edit the YAML above before copying.

Notes

  • -d (detached) has no Compose key: start the stack with "docker compose up -d".
  • Custom networks are declared as "external: true", meaning they must already exist (docker network create <name>). Remove that line to let Compose create them.

How to convert docker run to docker compose

  1. Paste your command. Multi-line commands ending in \, quoted values and a leading $ or sudo are handled.
  2. Check the YAML, the unsupported flags and any secret warnings, and edit the YAML if needed.
  3. Copy it or download docker-compose.yml, then run docker compose up -d in the same folder.

Worked example

docker run -d --name web -p 8080:80 -e TZ=UTC --restart unless-stopped nginx:1.27 becomes a web service with image: nginx:1.27, container_name: web, ports: - "8080:80", environment: - TZ=UTC and restart: unless-stopped. The -d flag is not part of the file; it is the -d in docker compose up -d.

Compose files are YAML: check or convert one with the YAML to JSON converter. Volume paths on Linux hosts may need the chmod calculator. More converters: JSON to TypeScript, CSV to JSON and diff checker. Always verify the result with docker compose config.

Frequently Asked Questions (FAQ)

How do I convert docker run to docker compose?

Paste the whole docker run command, including multi-line commands that end in a backslash. The tool turns each flag into the matching Compose key (ports, volumes, environment, restart and so on) and shows a docker-compose.yml you can edit, copy or download. Then run docker compose up -d.

Is my command uploaded anywhere?

No. The conversion runs entirely in your browser and nothing is sent to a server. Even so, avoid pasting real passwords or tokens into any website; use placeholders and an env file.

Which flags are not converted?

Flags with no Compose equivalent, such as -P, --rm, --ip and --network-alias, are listed under Unsupported flags with the reason, never dropped silently. -d is explained as docker compose up -d. Unknown flags are assumed to take no value; write them as --flag=value if they do.

Why does the tool warn about secrets?

Environment values that look like passwords, tokens or keys would end up in a plain-text YAML file that is easy to commit by mistake. Move them to an env_file kept out of version control, or reference a variable such as ${DB_PASSWORD} that Compose reads from a .env file.

What happens to named volumes and custom networks?

A named volume (-v data:/data) is added to the top-level volumes section. A custom network (--network mynet) is added as an external network, which must already exist; remove external: true to have Compose create it. host, none and bridge become network_mode.

Why did a dollar sign turn into two?

In Compose files a single $ starts variable interpolation. A $ that was literal in your shell command (inside single quotes) is written as $$ so it stays literal. Shell variables such as $HOME are left as written and Compose reads them from your environment.

Can I convert several docker run commands at once?

Yes. Put each command on its own line (or separate lines with no trailing backslash) and each becomes a service in the same file, with unique service names.

Does it support every Compose feature?

No. It covers the common docker run options. Check the result against the Compose file reference, especially for networking, resource limits and GPUs, and validate it with docker compose config.