Skip to content
Categories
docker run to docker-compose Converter
Convert a docker run command into a docker-compose.yml service definition.
Overview
- Parses a docker run command — one you're running locally or one written in a setup guide — and converts it into the corresponding docker-compose.yml service definition (YAML).
- Supports --name (container name), -p (published ports), -e (environment variables), -v (volumes), -w (working directory), and --restart (restart policy).
- If --name is not specified, the service name is inferred from the image name.
Usage
- Paste the docker run command into the input field.
- Click the "Convert" button.
- The corresponding docker-compose.yml service definition is displayed.
Example
Input
docker run -d --name web -p 8080:80 -e ENV=production nginx:latest
Output
services:
web:
image: nginx:latest
container_name: web
ports:
- 8080:80
environment:
- ENV=production
Use Cases
- Migrating a manually run docker run command into a docker-compose.yml
- Rewriting a docker run example from a README or blog post's setup instructions into Compose format
- Preparing to combine multiple docker run commands into a single docker-compose.yml
FAQ
How is the service name determined?
If --name is specified, that value is used; otherwise it is inferred from the image name (excluding the tag and registry host).
Are there docker run options that aren't supported?
Yes. Advanced options like --network, --link, and health-check-related flags are not supported. This tool is intended for converting basic options.
Can multiple docker run commands be combined into one file?
No. This tool converts one docker run command into one service definition. To combine multiple services, manually merge the outputs into a single file.
Notes
- The generated YAML does not include a `version` key, since recent Docker Compose versions following the Compose Specification recommend omitting it.
- The output performs only a basic conversion. Review and add settings like networks or health checks as needed for your actual setup.
Related Tools
Convert a curl command into JavaScript fetch() code.
Format YAML to make it easier to read.
Format HTML to make it easier to read.