Docker Run to Docker Compose Converter
Convert docker run commands to docker-compose.yml format with proper YAML structure and service configuration.
Docker Run to Docker Compose Converter tool
Example
Input: docker run -d --name web -p 8080:80 -v ./html:/usr/share/nginx/html --restart unless-stopped nginx:alpine
Result: services: web: with image nginx:alpine, container_name web, ports '8080:80', volumes ./html:/usr/share/nginx/html, restart unless-stopped
Each flag maps to its Compose key (-p to ports, -v to volumes, --restart to restart). -d is dropped because docker compose up -d handles detaching.
docker run Flags and Their Compose Keys
| docker run flag | Compose key |
|---|---|
| -p, --publish | ports |
| -v, --volume | volumes |
| -e, --env | environment |
| --env-file | env_file |
| --name | container_name |
| --restart | restart |
| -h, --hostname | hostname |
| -w, --workdir | working_dir |
| -u, --user | user |
| -l, --label | labels |
| --network (named) | networks, declared as external |
| --network host, none or bridge | network_mode |
| --cpus, -m / --memory | deploy.resources.limits |
| -i, -t | stdin_open, tty |
| -d, --rm, -P | dropped |
Mappings taken from this converter's flag tables.
- Paste your complete docker run command (including all flags like -p, -v, -e, --network) into the input area.
- The tool automatically parses the command and maps each flag to its docker-compose.yml equivalent.
- Review the generated YAML output to verify the service name, ports, volumes, and environment variables are correct.
- For multi-container setups, paste additional docker run commands on separate lines to generate a multi-service Compose file.
- Click the Copy button above the output to copy the complete docker-compose.yml content to your clipboard.
- Save the output as a docker-compose.yml file in your project directory and run it with docker compose up.
From docker run to docker-compose.yml
This converter turns docker run commands into a docker-compose.yml file. Each flag maps to its Compose key: -p becomes ports, -v becomes volumes, -e becomes environment and --restart becomes restart. The result follows the current Compose Specification, so it has no top-level version key.
A long docker run command is hard to read, easy to mistype and lives only in your shell history. A Compose file describes the same container as YAML that you can commit to Git, review and start with one command: docker compose up -d. It also makes it easy to add more services later, such as a database next to your app.
The parser reads the command the way a shell would. It understands single and double quotes, backslash line breaks, --flag=value forms and combined short flags such as -it. Anything after the image name becomes the command, kept as a list so arguments with spaces survive.
Flags such as -d, --rm and -P have no Compose equivalent and are dropped. --cpus and --memory go under deploy.resources.limits. --network host becomes network_mode, while a named network is listed under networks and declared at the bottom as external. Named volumes, as opposed to host paths, get a top-level volumes section.
Paste several commands, one per line or joined with &&, to get one service per command. Service names come from --name or the image name, with -2 or -3 added if two clash. Flags the tool does not map, such as --gpus, --mount or --log-opt, are skipped, so compare the output with your original command before you rely on it. To tidy the YAML afterwards, use the YAML Formatter.
Sources
Frequently Asked Questions
Related Tools
YAML Formatter and Viewer
Format, validate, and visualize YAML documents with tree view and customizable indentation.
Developer ToolsJSON to YAML Converter
Convert JSON documents to YAML format with syntax validation, clean formatting, and instant preview.
Developer ToolsCrontab Generator
Visually build cron expressions with dropdowns, see human-readable descriptions, and preview the next 5 run times.
DevOps ToolsGit Cheatsheet
Searchable interactive Git command reference organized by workflow - branching, merging, rebasing, and more.
DevOps Tools