BackendBench
Coffee
Free tool

docker run โ†’ Compose

Paste a docker run command and get an equivalent docker-compose.yml service definition.

docker-compose.yml

Turning a docker run command into a Compose service

Containers are often introduced to a project with a README line such as docker run -d -p 8080:80 -e MODE=prod nginx. That works until the command grows a dozen flags, a second container joins, or a colleague needs to run it the same way. Compose files fix that: the same settings, readable, reviewable and reproducible.

Paste a docker run command (with line continuations if it has them) and the converter produces a docker-compose.yml. It understands the quoting rules of a shell, combined short flags such as -it, the --option=value form and the attached form -p8080:80. Ports, volumes, environment variables, restart policy, limits and health checks are mapped to their Compose keys, and everything after the image name becomes the service command.

Details that matter

Review the result before using it; options that depend on the Docker host, such as devices and security settings, deserve a second look. Conversion happens locally in your browser.

Frequently asked questions

Why move from docker run to Compose?

A long docker run command is hard to read, review and repeat. A Compose file records the same configuration declaratively, can live in version control, and lets you start several containers together with docker compose up.

Which options are converted?

Ports, volumes, environment variables and env files, name, restart policy, network, working directory, user, hostname, labels, entrypoint, memory and CPU limits, capabilities, extra hosts, healthcheck options and tty/stdin. Unknown options are listed so nothing disappears silently.

What happens to --rm?

Compose has no equivalent for a service definition. Use docker compose run --rm service for one-off containers that should be deleted afterwards.

Do named volumes need declaring?

Yes. A named volume used by a service must also appear under the top-level volumes: key. The converter adds it for you.

More tools you might need