All tools

Docker Run to Docker Compose Converter

Code

Convert docker run commands into a docker-compose.yml, or a compose file back into docker run commands: ports, volumes, env, networks, healthchecks, GPUs and limits

Loading tool…
Was this tool helpful?
dockerdocker-composecomposedocker-runcontainerdevopsyamlconverter

About Docker Run to Docker Compose Converter

Paste a docker run command from a README or your shell history and get the equivalent compose.yaml service, or flip the direction and turn a docker-compose.yml into the plain docker commands that start the same containers. In the docker run to Compose direction it reads the command the way a shell would, so backslash continuations, quotes, combined flags like -it and attached values like -p8080:80 all work, and every flag with no Compose field (like --rm) is listed instead of dropped. In the Compose to docker run direction you get the network and volume create commands, a docker build for each build: service and one docker run -d per service in depends_on order, with anchors and merge keys resolved, relative bind mounts made absolute and ${VARIABLES} left for your shell. Both directions run in your browser and nothing is executed.

How to use Docker Run to Docker Compose Converter

  • 1.Pick a direction. For docker run to Compose, paste one or more docker run commands, one per line or joined with &&. For Compose to docker run, paste a compose.yaml or drop the file on the input.
  • 2.Read the output and the warnings under it: flags Compose can't express, $(...) substitutions it won't run and external networks in one direction; secrets, replicas, Swarm-only deploy keys and depends_on conditions docker run can't wait for in the other.
  • 3.Copy the result or download it as compose.yaml or run.sh. Check a compose file with docker compose config; run the docker commands from the folder that holds the compose file, after exporting any variables your .env file sets.

Frequently asked questions

How does it convert a docker-compose.yml back to docker run?
Each service becomes one docker run -d command with --name set to its container_name or service name. When there are several services it first creates a <project>_default network and puts every container on it, so they still reach each other by service name, and services start in depends_on order. Services with build: get a docker build -t <project>-<service> command first, extra networks are joined with docker network connect, and deploy.resources limits and GPU reservations become --cpus, --memory and --gpus.
What happens to ${VARIABLES}, $$ and relative paths?
In Compose to docker run, ${VAR} and $VAR stay in double quotes for your shell to expand, but docker run never reads .env, so export those variables first. $$ (Compose's escaped dollar) becomes a literal $ in single quotes, and ./data becomes ${PWD}/data because docker run wants absolute bind-mount paths. In docker run to Compose, a $ the shell kept literal becomes $$ and a leading $(pwd) becomes ".".
What can't be converted?
From docker run, flags with no Compose field such as --rm, -P or --cidfile are listed as warnings. From Compose, secrets, configs, extends, develop, profiles, deploy.replicas and Swarm-only deploy keys have no docker run flag, so they are reported instead of guessed at, and depends_on conditions like service_healthy are not enforced because docker run doesn't wait. The output targets a POSIX shell such as bash or zsh, not PowerShell.
Why is there no version: line at the top of the YAML?
The version key is obsolete in the current Compose Specification, and Docker Compose v2 prints a warning when it is present. The output works as-is with docker compose (v2); very old docker-compose v1 installs may need a version: "3.8" line added.

Use via API, SDK, or MCP

cURL# Free: 1,000 req/day · Pro: 10,000 req/day
curl -X POST https://api.utilix.tech/v1/tools/docker-run-to-compose \
  -H "Authorization: Bearer utx_live_..." \
  -H "Content-Type: application/json" \
  -d '{"command":"docker run -d --name web -p 8080:80 -v ./html:/usr/share/nginx/html:ro -e TZ=UTC --restart unless-stopped nginx:alpine"}'

Get an API key from your dashboard · Full API docs →