How to use docker run to docker-compose
The docker run to docker-compose converter turns a long, flag-heavy docker run command into a clean docker-compose.yml service, instantly in your browser. Paste the command you normally type in the terminal and the tool parses its ports, environment variables, volumes, restart policy, network, working directory and more, then emits the equivalent Compose service block. Moving a container from an ad-hoc CLI invocation to a versioned Compose file makes it reproducible, reviewable and easy to extend — and because the parsing happens locally, your commands and any secrets they contain never leave the page.
- Copy the full docker run command, including all its flags.
- Paste it into the input area.
- The equivalent docker-compose.yml service is generated automatically.
- Review the mapped ports, environment, volumes and other keys.
- Copy the YAML into your docker-compose.yml and run docker compose up.
Your data never leaves your device — 100% private processing.
How flags map to Compose keys
Each docker run flag has a direct counterpart in the Compose service schema, and the converter applies the standard mapping. Published ports from -p or --publish become entries under ports, environment variables from -e or --env become environment entries, and bind mounts or named volumes from -v or --volume become volumes. The --name flag sets both the service name and container_name, --restart sets the restart policy, --network adds the service to a network, and -w/--workdir, --entrypoint, -u/--user, --hostname and -l/--label map to working_dir, entrypoint, user, hostname and labels respectively. Any arguments that appear after the image name are collected into the command field so the container starts exactly as it did from the CLI.
| docker run flag | Compose key |
|---|---|
| -p / --publish | ports |
| -e / --env | environment |
| -v / --volume | volumes |
| --name | container_name |
| --restart | restart |
| --network | networks |
| args after image | command |
Single service vs a full stack
A docker run command starts exactly one container, so the converter emits exactly one service under the services key. Real applications often need several containers — for example a web app plus a database and a cache — and Compose is designed for precisely that. To build a multi-service stack, run each docker run command through the tool and combine the resulting service blocks into a single docker-compose.yml, indenting each under the shared services key. You can then add cross-cutting configuration such as a shared network, depends_on ordering, or named volumes that several services reference. The output deliberately omits the top-level version field because Compose v2 treats it as obsolete and will warn if it is present.
Worked examples
Basic web server
Inputs: docker run -d -p 8080:80 nginx
Result: A service “nginx” with image nginx and ports 8080:80.
With env and volume
Inputs: docker run --name db -e POSTGRES_PASSWORD=x -v data:/var/lib/postgresql/data postgres
Result: A service “db” with environment and volumes mapped.
Glossary
- docker run
- The Docker CLI command that creates and starts a single container from an image with a set of flags.
- docker-compose.yml
- A YAML file describing one or more services so a whole application can be started with a single command.
- Service
- A named container definition inside a Compose file, including its image and runtime configuration.
- Bind mount
- A volume mapping that connects a host path to a path inside the container, written as host:container.
- Restart policy
- A rule such as unless-stopped that tells Docker when to automatically restart a container.
Related reading
Frequently Asked Questions
Why use docker run to docker-compose?
- Convert a docker run command to a Compose service in one paste
- Maps ports, env vars, volumes, restart, network, workdir and labels
- Produces modern Compose v2 output with no obsolete version key
- Derives a sensible service name from --name or the image
- Runs entirely client-side, so commands and secrets stay local
Common use cases
- Migrate a container from a shell script to a versioned compose file
- Document how a container is run in a reviewable YAML format
- Bootstrap a multi-service stack one container at a time
- Share a reproducible setup with teammates instead of a CLI snippet
- Convert README “docker run” instructions into a compose example
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Related Developer Tools
Crontab Expression Generator & Explainer
Generate valid 5-field crontab expressions with a visual builder, decode existing cron syntax, and preview the next five local run times with clear validation.
File to Data URI
Upload any file and get a standards-compliant data URI instantly. Includes raw Base64, URL-safe Base64, and the full data URI — all in-browser and private.
YAML ↔ JSON Converter
Convert YAML to JSON and JSON to YAML online. Validate syntax instantly with error messages. Free, private converter that runs in your browser.
cURL Converter
Convert a curl command to JavaScript fetch, Node, Python requests, or PHP. Paste your curl and get clean client code instantly. Free and private.
.gitignore Generator
Generate a .gitignore file for your project. Pick languages, frameworks, and tools to build a ready-to-use git ignore file. Free and private.
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
Explore all Developer Tools.