docker run to docker-compose.yml Converter
Paste a docker run command and get a docker-compose.yml (Compose file). Ports, volumes, environment variables, container name, restart policy and other common options are converted, and named volumes and custom networks are declared at the top level for you. Anything that cannot be converted is listed as a warning. You can tidy the generated YAML with the YAML Formatter.
🔒 Runs in your browser · Your data is never sent to a server
Notes
- Supported options include -p, -v, -e, --env-file, --name, --restart, -w, -u, -h, --network, --entrypoint, -l, --cap-add, --cap-drop, --dns, --add-host, --device, --tmpfs, --expose, --link, -m, --cpus, --platform, --shm-size, --privileged, --init, --read-only, -i and -t. Everything else, such as --rm, health checks, logging options and --mount, is reported as a warning.
- Conversion goes one way only, from docker run to Compose. The command is never executed, and no image is pulled or container started.
- Shell expansion such as $(pwd) cannot be evaluated. $(pwd) and $PWD in volumes become the relative path ".", and any other "$" is output unchanged.
- Passwords and tokens given with -e appear in the output. Check it before sharing or publishing (values are never stored or sent anywhere).
- -d (detached mode) has no Compose equivalent in the file; use docker compose up -d instead, so it is omitted.
Glossary
Docker Compose
A tool that describes one or more containers in a YAML file (compose.yml / docker-compose.yml) and starts them with docker compose up. Keeping your docker run options in a file makes the setup easy to reproduce.
Named volume
A volume given by name instead of a path, as in -v pgdata:/var/lib/postgresql/data. In Compose it is declared under the top-level volumes: key. A source starting with / or . is a bind mount of a host path.
network_mode
The Compose setting that corresponds to docker run --network host and similar. A custom network name goes under networks:, marked external: true when it was created outside Compose.
FAQ
Which docker run options are supported?
Common ones: -p, -v, -e, --env-file, --name, --restart, -w, -u, --network, --entrypoint, --cap-add, --privileged, -i and -t, among others. Options such as --rm, health checks, logging settings and --mount are not converted and are listed as warnings.
How is -v $(pwd):/app converted?
A browser cannot evaluate shell expansion, so $(pwd), $PWD and ${PWD} are replaced with the path "." relative to the compose file (for example ./data:/data). Docker Compose resolves relative paths against the directory containing compose.yml.
Are named volumes declared automatically?
Yes. A source given as a name rather than a path, as in -v pgdata:/data, is added under the top-level volumes: key. A custom network passed to --network is likewise added under networks: with external: true.
Are values like "true" or 3000 quoted in the YAML?
Yes. In YAML, true, no and numbers would otherwise stop being strings, so such values are written in double quotes. restart: "no" is handled the same way. Compose expands $VARIABLES, so write $$ for a literal dollar sign.
Can I convert docker-compose.yml back to docker run?
No. This tool only goes from docker run to Compose. Converting a multi-container Compose file back to commands is not supported.
Share this page
