Docker Run to Compose: Convert docker run to compose.yml
Docker run to Compose converter online: generate compose.yml from docker run commands with ports, volumes, and environment variables.
Updated 2026-08-16
Related Tools
Docker Compose to Run: Convert compose.yml to docker run
YAML to JSON: Convert Docker/K8s Config Files Online
JSON Formatter: Beautify, Validate & Minify JSON Online
Alt Text Generator: Image Accessibility & WCAG Descriptions
Cron Generator: Build Linux Crontab Schedule Online
RSA/ECDSA Key Generator: PEM Keys for SSH, TLS & JWT
Features
- Instant conversion: paste a docker run command and get a valid Compose v3 docker-compose.yml in real time
- Supports all common flags: -p, -v, -e, --name, --restart, --net, --rm, -d, including multiple -e environment variables in one command
- Handles named volumes, bind mounts, and volume options like :ro (read-only)
- Maps network modes: bridge, host, none, and custom network names
- Preserves container naming via container_name field for easy identification
- Handles image tags and digests: nginx:latest, postgres:14, ubuntu@sha256:abc123...
- One-click copy to clipboard and download as docker-compose.yml file
- 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, and adjust YAML indentation (2 or 4 spaces)
- Merge with existing docker-compose.yml: paste your file and append new services
- Entirely client-side: your docker commands never leave the browser
How to Use
- 1Paste your docker run command into the input area, and 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 tool lets you choose between three output versions: Latest (Common Specification, recommended), v3.x, and v2.x. The choice affects whether a version field is included and formatting details. The default Latest output is compatible with Docker Compose v2.x and v3.x and omits the version field, so modern Compose infers it automatically, which is the approach the official Docker documentation recommends.
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.
How do I run the generated docker-compose.yml file?
Save the output as docker-compose.yml in your project folder, then run docker compose up -d to start the services in the background. To preview what will be created first, run docker compose config to validate the file; it prints the resolved configuration or the exact YAML error. On older setups using the standalone binary, use docker-compose up -d instead.
Why does my container get a different network or hostname with compose than with docker run?
By default, docker compose creates a dedicated bridge network for the project and uses the service name as hostname, while docker run puts the container on the default bridge with a random container ID hostname. If your command used --net host or a custom network, the conversion maps it to the compose network section. Create the custom network first with docker network create if it does not exist, or check docker compose up logs for network errors.
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.
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.
Why does my converted service exit immediately when I run docker compose up?
That is expected for one-shot containers: a command like docker run --rm alpine echo hi starts, prints, and exits; compose faithfully reproduces that, so the service stops when the process ends. For one-off tasks, run docker compose run <service> instead of up, which behaves like docker run. If the container should stay alive, check that the image has a long-running entrypoint and that you did not convert a --rm one-off command by mistake.
Why does my password or config value with a $ sign come out wrong after conversion?
Compose interpolates $VAR references in the file at startup, so a literal $ in a value (a password, a JDBC URL) must be written as $$ in compose. The tool quotes values for YAML validity, but it cannot know which $ signs you intend to be literal. After conversion, replace intentional $ characters with $$ inside values, or keep secrets out of the compose file entirely and pass them through an .env file.