Docker Run to docker-compose.yml Converter
Translate multi-line docker run CLI commands with ports, bind volumes, env files, GPUs, resource limits, and restart policies into clean docker-compose.yml files.
Input & Options
Local JS Execution
Parsed Output & Diagnostics
Ready
Status
...
Generated Output
Common docker run Flag Mapping
| CLI Flag | Compose Key | Notes |
|---|---|---|
| -p 8080:80 | ports: | Quoted "8080:80" prevents YAML sexagesimal parsing |
| -v name:/path | volumes: + top-level volumes: | Named volumes get top-level declaration automatically |
| --cpus / -m | deploy.resources.limits | Standard Compose v2/v3 CPU & memory limit block |
| --gpus all | deploy.resources.reservations.devices | Uses NVIDIA driver count: all reservation |
Parser Methodology & Privacy Guarantees
Runs a full POSIX-style shell tokenizer supporting single quotes, double quotes, escapes, and line continuations, then extracts container flags vs. image & command arguments.
- Tokenizes the shell string without invoking eval or server calls.
- Maps short flags (-p, -v, -e, -u, -w, -m, -h, -l) and GNU long equivalents (--flag=val or --flag val).
- Emits quoted YAML port strings, named top-level volumes, external network stubs, and GPU reservation blocks.
Scope & limitations: Very rare flags like --mount type=bind or --device-cgroup-rule are noted in diagnostics as unrecognized so nothing fails silently.
Frequently Asked Questions
Why should Compose ports always be quoted as strings?
YAML 1.1 parsers interpret unquoted values like 22:22 or 80:80 below 60 as base-60 integers, corrupting port mappings. Quoting ports avoids subtle deployment bugs.
Why does Compose v2 omit version: '3.8'?
Since Docker Compose v2, the top-level version attribute is deprecated and generates warnings. Leave it unchecked unless maintaining legacy docker-compose v1 scripts.
Does this handle inline secrets in -e flags safely?
Everything stays in your browser tab, and the analyzer flags sensitive env keys so you can move secrets into env_file before committing docker-compose.yml.