Tools / docker run to docker-compose

docker run to docker-compose.

Convert one or more docker run commands into a docker-compose.yml with ports, volumes, env and healthchecks.

Runs in your browser

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result
docker-compose.yml
Notes

About docker run to docker-compose

docker run to docker-compose converts the long docker run commands from READMEs and shell history into a compose file you can commit. The command is split the way a POSIX shell would: single and double quotes, backslash escapes and line continuations are honoured, so -e "GREETING=hello world" stays one value and a command spread over lines with trailing backslashes works. Several commands, one per line or joined with &&, become several services, and other commands such as docker network create are skipped. Every docker run option with a compose equivalent is mapped: --name to the service and container_name, -p to ports, -e and --env-file to environment, -v and --mount to volumes, --network and --network-alias to networks, --restart, --user, --workdir, --entrypoint, labels, extra hosts, DNS, capabilities, devices, logging, memory and CPU limits, ulimits, sysctls, the --health-* flags to a healthcheck block and --gpus to a device reservation. Anything after the image becomes the command list, keeping each argument exactly as the shell passed it. Named volumes and user-defined networks are declared at the top level; networks are marked external because docker run expects them to exist already. Options with no compose field, such as --rm and -d, are listed in the notes instead of being dropped silently, and unknown options are reported with their position so typos are caught. Ports and values that YAML could misread are quoted. The conversion runs in your browser.

How to Use

  1. Paste one or more docker run commands.
  2. Read the notes for options that compose cannot express.
  3. Copy the YAML into docker-compose.yml and run docker compose up.

Frequently Asked Questions

Why are networks marked external?

With docker run you create user-defined networks beforehand (docker network create). external true tells compose to use that existing network instead of creating a new project-scoped one.

What happens to --rm and -d?

Compose manages the container lifecycle itself, so they have no field. Use docker compose up -d to run in the background; both options are listed in the notes.

Will my named volume keep its data?

Compose prefixes volume names with the project name, so it creates a new volume. Add external true under the volume to reuse the one docker run created.

Is the command sent to a server?

No. Parsing and conversion run in your browser.

Related Tools