Docker Run to Docker-Compose Converter
Paste a docker run command and instantly get a valid docker-compose.yml file. Supports ports, volumes, environment variables, networks, restart policies, resource limits, and more.
How Does the Docker Run to Docker-Compose Converter Work?
The Docker Run to Docker-Compose Converter is a free online tool that transforms long, complex docker run commands into clean, version-controlled docker-compose.yml files. When you are prototyping with Docker, you often start with a quick docker run command in your terminal. As your setup grows with multiple flags for ports, volumes, environment variables, and network settings, that single command becomes unwieldy and hard to reproduce. Docker Compose solves this by letting you define your container configuration in a declarative YAML file that can be committed to version control and shared with your team.
This tool parses the full range of docker run flags including port mappings (-p), volume mounts (-v), environment variables (-e), container names (--name), restart policies (--restart), network configuration (--network), working directories (-w), entrypoints (--entrypoint), memory and CPU limits, labels, privileged mode, environment files, and linked containers. It handles multiple instances of the same flag, quoted values, and multi-line commands that use backslash continuation characters.
Why Convert Docker Run to Docker-Compose?
Docker Compose offers several advantages over raw docker run commands. First, YAML files are self-documenting and easy to read. A team member can glance at a docker-compose.yml and understand the entire container setup without deciphering a 200-character terminal command. Second, Compose files are version-controlled, so you get a history of configuration changes. Third, Docker Compose supports multi-container applications natively, letting you define databases, caches, and application servers in a single file and start them all with docker compose up.
Supported Docker Run Flags
-p, --publish— port mappings (host:container)-v, --volume— volume mounts (host:container or named volumes)-e, --env— environment variables (KEY=VALUE)--name— container name--restart— restart policy (no, always, unless-stopped, on-failure)--network, --net— network name-w, --workdir— working directory inside the container--entrypoint— override the default entrypoint-m, --memory— memory limit--cpus— CPU limit-l, --label— container labels--privileged— privileged mode--env-file— load environment variables from a file--link— link to another container
The converter handles edge cases like multi-line commands with backslash continuations, quoted environment variable values, and mixed short and long flag formats. If a flag cannot be parsed, the tool reports exactly what was understood and what was skipped, so you can adjust your input accordingly.
Frequently Asked Questions
What docker run flags does this converter support?
The converter supports all commonly used docker run flags including -p (ports), -v (volumes), -e (environment variables), --name, --restart, --network, -w (workdir), --entrypoint, -m (memory), --cpus, -l (labels), --privileged, --env-file, --link, and -d (detach). The -d flag is noted but not included in compose output since compose runs detached by default.
Does this tool handle multi-line docker run commands?
Yes. If your docker run command spans multiple lines using backslash (\\) continuation characters, the converter joins them into a single command before parsing. Simply paste the multi-line command as-is and it will be processed correctly.
What docker-compose versions are supported?
You can choose between Compose file versions 3.8, 3.9, and 2.4. Version 3.8 is the most widely used and recommended for most setups. Version 2.4 supports additional features like memory and CPU limits directly under the service definition without the deploy key.
How are resource limits handled in the compose output?
For Compose version 2.4, memory and CPU limits are placed directly under the service (mem_limit, cpus). For versions 3.8 and 3.9, they are placed under the deploy.resources.limits section, which is the correct format for Docker Swarm-compatible configurations. Use docker compose up with --compatibility flag to apply deploy limits in non-Swarm mode.
Is my docker run command sent to any server?
No. This tool runs entirely in your browser. Your docker run command is parsed locally using JavaScript and never leaves your machine. No data is sent to any server, making it safe to convert commands that contain sensitive environment variables or internal hostnames.