Docker Run to Compose — Convert run to compose.yml
Convert docker run to docker-compose.yml instantly. Supports ports, volumes, env vars, networks, and restart policies. Free browser tool, no data uploaded.
Features
- ✓Instant conversion — paste a docker run command and get a valid docker-compose.yml in real time
- ✓Supports all common flags: -p (ports), -v (volumes), -e (environment), --name, --restart, --net, --rm, -d
- ✓Handles named volumes, bind mounts, and volume options like :ro (read-only)
- ✓Maps network modes — bridge, host, none, and custom network names
- ✓Generates proper Compose v3 format with services, ports, volumes, and environment sections
- ✓Preserves container naming via container_name field for easy identification
- ✓Supports multiple environment variables in a single command (-e KEY1=VAL1 -e KEY2=VAL2)
- ✓Handles image tags and digests — nginx:latest, postgres:14, ubuntu@sha256:abc123...
- ✓One-click copy to clipboard and download as docker-compose.yml file
- ✓Entirely client-side — your docker commands never leave the browser
- ✓Works with docker create, docker container run, and podman run command prefixes
- ✓Shows parsed flags summary so you can verify what was extracted before copying
- ✓Choose Compose version — Latest (Common Spec), v3.x, or v2.x
- ✓Adjustable YAML indentation — 2 or 4 spaces
- ✓Merge with existing docker-compose.yml — paste your file and append new services
How to Use
- 1Paste your docker run command into the input area — the docker-compose YAML output appears instantly.
- 2The tool auto-detects the command prefix: docker run, docker create, docker container run, or podman run.
- 3Check the parsed flags panel to verify which options were extracted from your command.
- 4Click the Copy button to copy the generated docker-compose.yml to your clipboard.
- 5Download the output as a docker-compose.yml file with the Save button.
- 6Use the Clear button to reset both input and output for a new command.
- 7Try the example buttons below the input to see common conversion scenarios.
- 8Paste multi-line commands — the tool handles backslash continuations and extra whitespace.
- 9For multiple containers, paste each docker run command separately and combine the output manually.
- 10Use the Version toggle in the toolbar to switch between Latest, v3.x, and v2.x Compose formats.
- 11Use the Indent toggle to switch between 2 and 4 space indentation in the YAML output.
- 12Click 'Merge with existing compose' to paste an existing docker-compose.yml and append new services from docker run commands.
Frequently Asked Questions
What is docker run to docker-compose conversion?
∨
It converts a docker run CLI command into a docker-compose.yml configuration file. Instead of running long docker run commands with many flags, you get a structured YAML file that defines your container's image, ports, volumes, environment variables, and other settings. This makes it easier to manage, version-control, and share your container configurations.
Which docker run flags are supported?
∨
The tool supports all common flags: -d (detach), --name (container name), -p / --publish (port mapping), -v / --volume (volume mounts), -e / --env (environment variables), --restart (restart policy), --net / --network (network mode), --rm (auto-remove), --hostname, --working-dir / -w, --entrypoint, --user / -u, --hostname, --label / -l, --add-host, --dns, --memory / -m, --cpus, and more. Flags without recognized equivalents are noted in the parsed summary.
Can I convert docker create commands too?
∨
Yes. The tool recognizes docker run, docker create, docker container run, and podman run as input prefixes. The conversion logic is the same since docker create and docker run share the same flag syntax — the only difference is that docker run starts the container immediately.
Does it support docker compose v2 or v3?
∨
The generated output uses Docker Compose v3+ format (the Common Specification), which is compatible with Docker Compose v2.x and v3.x. The output does not include a version field, as modern Docker Compose automatically infers the correct version. This is the recommended approach per the official Docker documentation.
How are volume mounts converted?
∨
Bind mounts like -v /host/path:/container/path become volumes entries in the compose file. Named volumes like -v mydata:/var/lib/data are recognized and listed under both the service volumes and a top-level volumes section. Read-only mounts (-v ./data:/app/data:ro) are preserved with the :ro flag.
Can I convert commands with multiple flags?
∨
Absolutely. You can paste a single docker run command with any combination of flags — ports, volumes, environment variables, network settings, restart policies, labels, and more. All flags are extracted and mapped to their compose equivalents in one conversion.
What happens with unsupported flags?
∨
If a flag doesn't have a direct compose equivalent (like --privileged or --cap-add), the tool includes it in the parsed flags summary so you know it was detected. You can then manually add it to the compose file using the extra_hosts, cap_add, or other extension fields that Docker Compose supports.
Is my data safe and private?
∨
Yes. All conversion happens entirely in your browser using JavaScript. Your docker commands are never sent to any server. The tool works offline after the initial page load. This is safe for sensitive commands that may contain passwords, API keys, or internal hostnames.
Can I convert docker-compose.yml back to docker run?
∨
This tool converts in the docker run → compose direction only. For the reverse (compose → docker run), check out Decomposerize or search for compose-to-run converters. Many developers use both directions depending on whether they're writing a new compose file or documenting an existing command.
Why use docker-compose.yml instead of docker run?
∨
docker-compose.yml provides several advantages: version control with Git, easy sharing with teammates, ability to start/stop entire application stacks with one command, dependency management (depends_on), network isolation, and consistent environments across development, staging, and production. It's the standard for multi-container applications.
Does it handle environment variables with special characters?
∨
Yes. Environment variables containing equals signs, spaces, or special characters are properly quoted in the YAML output. For example, -e DATABASE_URL='postgres://user:pass@host/db?sslmode=require' is correctly converted with appropriate YAML quoting to preserve the value.
Can I use this tool on mobile?
∨
Yes, the tool works on mobile browsers. However, for the best experience with long docker commands, we recommend using a desktop browser where you can easily paste multi-line commands and review the output side by side.
Which Compose versions are supported?
∨
The tool supports three Compose versions: Latest (Common Specification, recommended), v3.x, and v2.x. Different versions affect whether a version field is included and formatting details. Latest is recommended as it's compatible with all modern Docker Compose installations.
How do I add a docker run command to an existing compose file?
∨
Click the 'Merge with existing compose' toggle in the toolbar, paste your existing docker-compose.yml content, then enter your docker run command. The tool automatically merges the new service into the existing configuration while preserving all original services, volumes, and networks.
Can I change the YAML indentation?
∨
Yes. The toolbar provides 2 and 4 space indentation options. The default is 4 spaces; choose 2 for more compact YAML output.
Related Tools
Docker Compose to Run — Convert compose.yml to docker run
Convert docker-compose.yml to docker run commands instantly. Supports ports, volumes, env vars, networks, restart policies. Free browser tool, no data uploaded.
YAML to JSON — Convert Docker/K8s Config Files Online
Convert YAML to JSON and JSON to YAML with real-time validation. Supports Docker Compose, Kubernetes, CI/CD configs. Bidirectional with error detection.
JSON Formatter — Beautify, Validate & Minify JSON Online
Format, minify, pretty-print, and syntax-highlight JSON data. Features key sorting, custom indentation, tree view, error highlighting, and file upload.