Docker Run to Compose Converter
Turn a docker run command into a docker-compose.yml service definition
Input & Settings
docker-compose.yml
Generated docker-compose.yml will appear here
Analysis & Stats
Conversion statistics will appear here
About this tool
This tool parses a `docker run` command and emits an equivalent `docker-compose.yml` service definition. It maps the common flags — image, container name, published ports, volumes, environment variables, networks, restart policy, workdir, user, entrypoint, labels and command — to their Compose equivalents. The companion Docker Compose Builder (already in DevTools) goes the other direction visually. Use this when migrating one-off `docker run` invocations into a versioned Compose file. Parsing is client-side; no command is executed.
Examples & Use Cases
Web server with port mapping
# docker run command
docker run -d --name web -p 8080:80 nginx:latest
# docker-compose.yml
services:
web:
image: nginx:latest
container_name: web
ports:
- "8080:80"The container name becomes the service key; -p host:container maps to the ports list.
Database with env + volume
# docker run command
docker run -e POSTGRES_PASSWORD=secret -e POSTGRES_DB=app -v pgdata:/var/lib/postgresql/data postgres:15
# docker-compose.yml
services:
postgres:
image: postgres:15
environment:
POSTGRES_PASSWORD: secret
POSTGRES_DB: app
volumes:
- pgdata:/var/lib/postgresql/dataEnvironment flags become a key/value map; named volumes map to the volumes list.
Restart policy + network
# docker run command
docker run --restart unless-stopped --network mynet redis:7
# docker-compose.yml
services:
redis:
image: redis:7
networks:
- mynet
restart: unless-stopped--restart maps to the restart field; --network maps to the networks list.
Examples
Convert a basic nginx run command
docker run -d --name web -p 8080:80 nginx:latestservices:
web:
image: nginx:latest
container_name: web
ports:
- "8080:80"
restart: "no"
command: []The container name, published port mapping, and image tag are all mapped. The -d flag is noted; restart defaults to 'no' since no --restart flag was given.
Convert a command with volumes and environment
docker run -d --name db -v pgdata:/var/lib/postgresql/data -e POSTGRES_PASSWORD=secret --restart always postgres:16services:
db:
image: postgres:16
container_name: db
environment:
- POSTGRES_PASSWORD=secret
volumes:
- pgdata:/var/lib/postgresql/data
restart: always
volumes:
pgdata:The named volume pgdata is detected and the builder adds it to the top-level volumes: block. Bind mounts (./data:/app/data) are left as-is and not added to volumes:.
About this tool
Docker Run to Compose Converter takes a docker run command and emits a corresponding docker-compose.yml service definition. It parses the command using a quote-aware tokenizer so complex arguments — those containing spaces, equals signs, or multiple flags — are handled correctly before being mapped to their compose equivalents.
Mapped flags include --name, -p (publish), -v (volume), -e (environment), --restart, --network, -w (workdir), -u (user), --entrypoint, -l (label), --hostname, and the trailing command. Named volumes are automatically collected into the top-level volumes: block.
The YAML is generated entirely in your browser using js-yaml — no docker command is executed and nothing is uploaded.
How to use
Paste a docker run command
Enter or paste a docker run command into the input. The tokenizer handles quoted arguments and complex flag combinations.
Review the generated YAML
The output shows a docker-compose.yml service block, with named volumes gathered into the top-level volumes: section automatically.
Copy or download
Copy the YAML or download docker-compose.yml, then run docker compose up to start the service.
Use cases
Migrating a docker run script to Compose
Take an existing shell script full of docker run commands and convert each one into a Compose service, making the stack reproducible with docker compose up.
Documenting how a container was started
Capture the exact flags used to run a container as a Compose definition that can be committed to version control alongside the Dockerfile.
Quick Compose scaffolding
Sketch out a Compose service by typing the docker run command you already know, then refine the generated YAML in the editor.
Common mistakes
Mistake:Omitting quotes around port mappings with a host port.
Fix:YAML interprets 8080:80 as the number 42240 (8080 / 0.191). The builder quotes port strings automatically, but if you edit the output, always quote host:container mappings.
Mistake:Using a bind mount path as a named volume.
Fix:./data:/app/data is a bind mount (host path). data:/app/data is a named volume. The builder detects leading ./ as a bind mount and omits it from volumes:; named volumes are added automatically.
Frequently asked questions
Related guides
References & standards
Related tools
Driver's License Generator
Generate driver's license numbers in the correct format for 21 countries and all 50 US states, plus a format and Luhn validator — test data only, runs in your browser.
Address Generator
Generate realistic addresses in the correct format for 21 countries — single-line, multi-line, JSON or HTML — plus a postcode validator. Test data only, runs in your browser.
Phone Number Generator
Generate phone numbers in the correct format per country — mobile, landline and toll-free — in international, national, raw or tel: format, plus a validator. Test data only.
XML to JSON Converter
Convert XML data to JSON format with attribute handling, configurable parsing options, and live statistics
Markdown to HTML Converter
Convert Markdown to clean HTML with GitHub-Flavored Markdown, syntax highlighting, and optional sanitization
GitHub Actions YAML Generator
Generate GitHub Actions workflow YAML with triggers, jobs, and steps through a visual form