Docker Run to Docker Compose yml Converter

Convert long, complex docker run commands into clean docker-compose.yml files. Parses ports, volumes, environment variables, and restart policies locally.

Input docker run command:
Samples:
Compose Version:
Generated docker-compose.yml:
Embed this tool on your website / blog No code required · Copy and paste
HTML Embed Code (iframe):
<iframe src="https://lucentool.com/docker-run-to-compose" width="100%" height="650" style="border:1px solid #e5e0d8;border-radius:12px;max-width:850px;width:100%;" frameborder="0"></iframe>
<div style="font-size:12px;color:#78716c;margin-top:6px;font-family:sans-serif;">Powered by <a href="https://lucentool.com/docker-run-to-compose" target="_blank" style="color:#c85a32;text-decoration:none;">Lucentool - Docker Run to Docker Compose Converter</a></div>

Why Use Docker Compose Over docker run?

Deploying containers with standalone docker run commands is prone to human error when managing multiple ports, persistent volumes, and environment variables. Docker Compose declares your infrastructure as code in a single file, allowing reproducible deployments with docker compose up -d.

Common Parameter Mappings

How the conversion runs

parseDockerRun() first strips line continuations and collapses whitespace, then splits the command respecting quotes so a value with spaces survives intact. Each flag is mapped to its Compose equivalent — published ports, bind mounts, environment entries, container name, restart policy, network — and collected into a service object that is finally emitted as YAML with consistent indentation. The mapping is explicit rather than generic, which is why a flag it knows produces a correct field and a flag it does not know is reported instead of guessed at.

Edge cases and hard limits

Only the common flags are modelled. Device passthrough, capability additions, sysctls, the long-form mount syntax and multiple network aliases degrade or disappear, and --rm has no direct Compose field — it belongs in the run command, not the service definition. Dependency ordering and healthchecks are not inferred, because a single run command does not express them. The output is a starting point that still needs a docker compose config check.

Privacy: processed in your browser

The command string is parsed and reformatted in place. No container runtime is contacted, and the image names you paste are not resolved or pulled.

Frequently asked questions

Is the Compose file equivalent to my run command?

For the flags it models, yes. Anything exotic is dropped or reported, so treat the output as a first draft and diff it against the original intent.

How do I express --rm?

It has no service-level equivalent. Keep it in a wrapper script or use docker compose run, which removes the container when it exits.

Does it handle depends_on?

No. A run command carries no ordering information, so dependencies have to be added by hand once you split services.