What you can do with Docker Run to Docker Compose Converter
- Convert docker run to compose
- Generate compose file
How this developer utility works
Convert supported docker run options into a safely serialized Compose service. Unsupported flags and unquoted shell operators, redirects, or command substitutions produce an error instead of partial YAML.
Example input
docker run --detach --name web --publish 8080:80 --volume ./site:/usr/share/nginx/html:ro --env NODE_ENV=production --restart unless-stopped nginx:alpineExample output
services:
web:
image: nginx:alpine
restart: unless-stopped
container_name: web
ports:
- '8080:80'
volumes:
- ./site:/usr/share/nginx/html:ro
environment:
NODE_ENV: productionPractical workflow
- Paste one docker run command with its image and options; the parser accepts quoted values and line continuations but never executes shell text.
- Review the Compose service name, image, command, ports, mounts, environment, and runtime options before using it.
- Check variable interpolation and compare any unrecognized Docker behavior with the original command before starting the service.
- Copy or download the YAML, then use docker compose up -d to start the service detached.
Common use cases
- Migrate ad-hoc docker run commands from documentation into maintainable compose files.
- Standardize a container's ports, volumes, and env vars in version control.
- Combine several converted services into one compose stack.
Important notes and limitations
- Maps --name, publish and volume flags, environment values, restart, work directory, user, hostname, entrypoint, platform, labels, and interactive TTY flags; unknown options are rejected instead of silently omitted.
- No image, container name, or restart policy is invented. The --detach flag is handled by docker compose up -d; --rm cannot be represented in a service file and is reported as an error.
- The parser never executes shell text. It rejects unquoted shell operators, redirects, backticks, and $() substitutions; text inside quotes is preserved as a literal value. Docker Compose can still interpolate ${...} expressions when you use the YAML.
- The PostgreSQL preset contains REPLACE_WITH_STRONG_PASSWORD as a reminder; use a secret manager or an untracked environment file for real credentials.
Terminal & CLI equivalents
Docker run production container example
docker run -d --name web -p 8080:80 -v ./data:/data:ro --restart unless-stopped nginx:alpineRuns a background container with port forwarding, read-only volume, and restart policy.
Verify compose.yaml syntax
docker compose configValidates docker-compose.yml syntax and resolves environment variable references.
Docker Run Flags to Compose v2 Directives
| Docker Run CLI Option | Compose v2 Directive | Example CLI Syntax | Example Compose YAML |
|---|---|---|---|
| -p, --publish | ports: | -p 8080:80 | ports: - "8080:80" |
| -v, --volume | volumes: | -v /data:/app:ro | volumes: - /data:/app:ro |
| -e, --env | environment: | -e PORT=3000 | environment: - PORT=3000 |
| --restart | restart: | --restart unless-stopped | restart: unless-stopped |
| --network | networks: | --network app-net | networks: - app-net |
Common errors & troubleshooting
YAML Exception: mapping values are not allowed here
Cause: Indentation contains tab characters or a colon is missing a trailing space.
Solution: Use 2 spaces for indentation and ensure every key is followed by a space ('key: value').
Continue your workflow
- cURL to Code Converter — convert cURL healthcheck commands into application code.
- Cron Parser — schedule automated maintenance jobs and container restarts.
- SSH Key Generator — generate deploy keys for automated CI/CD container deployments.
- Diff Checker — compare staging and production docker-compose.yml definitions.
Frequently asked questions
How do I convert a docker run command to a Compose service?
Paste one command with its image and supported flags. The browser parses it and serializes a Compose service with the recognized options; review the YAML before starting containers.
Which docker run flags are converted?
It maps names, published ports, mounts, environment variables, restart policy, work directory, user, hostname, entrypoint, platform, labels, and interactive TTY flags. It reports unsupported flags instead of dropping them.
Does the converter execute shell commands or send the input to a server?
No. Parsing and YAML generation run in the browser; the converter never invokes a shell. It rejects unquoted shell operators, redirects, backticks, and $() substitutions, while preserving quoted text as a literal value. Docker Compose can later interpolate ${...} expressions when you use the generated file.