Skip to main content

Docker Run to Compose Converter

Turn a `docker run …` command into an equivalent docker-compose.yml service definition — ports, volumes, environment, networks, healthchecks, resource limits and more. Runs entirely in your browser.

Input

Output

docker-compose.yml
 
Was this helpful?

More ways to use this tool

REST API

curl -X POST https://api.iotools.cloud/v1/tool/docker-run-to-compose-converter \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "dockerRunInput": "docker run -d \\\n  --name nginx-proxy \\\n  --resta…"
  }'

Swap in your own key from your account. The tool's fields are the body — no wrapper.

Ask an AI agent

Use the IOTools `docker-run-to-compose-converter` tool (Docker Run to Compose Converter) on this input:

YOUR_INPUT_HERE

Paste this at any agent connected to the IOTools MCP server, then add your input.

Embed widget

<iframe
  src="https://iotools.cloud/embed/docker-run-to-compose-converter/"
  width="100%" height="520" frameborder="0" scrolling="no" loading="lazy"
  title="Docker Run to Compose Converter — iotools.cloud"
  sandbox="allow-scripts allow-forms allow-same-origin allow-downloads allow-popups allow-popups-to-escape-sandbox"
  allow="clipboard-write"
  style="width:100%;border:1px solid #e5e7eb;border-radius:12px;overflow:hidden"></iframe>
<script src="https://iotools.cloud/embed.js" async></script>

Drop this into your own page — free, no key required, just a link back.

Cost per API/MCP callFrom 5 credits

Also available with

Guides

The Docker Run to Compose Converter turns a long docker run … command into an equivalent docker-compose.yml service definition. Paste the command you would normally type in your terminal and get a ready-to-save Compose file — no more hand-translating dozens of -p, -v, and -e flags into YAML.

It is built for the moment you find a container in a project's README, a blog post, or your shell history and want to manage it declaratively instead. Compose files are easier to version, review, and restart than a wall of command-line flags.

How to use it

  1. Paste your full command into the Docker Run Command box, for example docker run -d --name web -p 8080:80 -v ./html:/usr/share/nginx/html nginx:alpine.
  2. The docker-compose.yml output updates as you type.
  3. Copy it or download it as docker-compose.yml, then run docker compose up -d in that directory.

Multi-line commands with trailing backslashes (\) paste in fine — the converter joins the continuation lines before parsing.

What gets converted

The tool understands the flags people actually use: -p/--publish (ports), -v/--volume (volumes), -e/--env and --env-file (environment), --name, --restart, --network, -l/--label, --user, --workdir, --entrypoint, capabilities (--cap-add/--cap-drop), --device, --dns, --add-host, tmpfs, --ulimit, --sysctl, and the health-check flags (--health-cmd, --health-interval, and friends). Resource flags — --memory, --memory-reservation, --cpus, --cpu-shares — are emitted under a deploy.resources block. Any image arguments after the image name become the service command.

FAQ

Does it produce a version key?

No. The top-level version: field is obsolete in the current Compose Specification and is intentionally omitted. Modern docker compose ignores it.

How are named networks handled?

A --network host, none, bridge, or container:<id> value maps to network_mode. Any other network name is treated as a user-defined network: it is added to the service's networks: list and declared at the bottom of the file as external: true, assuming you created it beforehand with docker network create.

Why is --cpu-shares divided by 1024?

Docker's CPU shares are relative weights where 1024 equals one full CPU. Compose's reservations.cpus expects a fractional core count, so the value is converted (for example 512 becomes "0.50").

Will it handle flags I do not recognize?

Flags with no Compose equivalent (such as --rm or -d) are simply dropped, since they describe how the CLI runs rather than the service itself. If the input does not begin with docker run, you get a short comment explaining that instead of a broken file.

Is it a full YAML validator?

No — it emits a clean, correctly quoted Compose file but does not schema-validate against the Compose Specification. Review the result before deploying.

Privacy

The conversion runs entirely in your browser. Your command — including any secrets in environment variables or labels — is never uploaded to a server. Because of that, avoid pasting production credentials, and treat the generated file the same way you would treat the original command.

dockerdocker-composecomposedocker runyamldevopscontainersconverter

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.