docker run to docker compose
Translate a docker run command into a Compose service: name, image, ports, environment, volumes, restart policy and command.
What the docker run to docker compose does
The command is tokenised and walked: -d is Compose's default and disappears, --name names the service (defaulting to app), and -p, -e, -v, --restart and --network become their Compose keys. Ports, environment entries and volumes are quoted so a colon in a value stays a value.
Everything after the image is joined back into command, which is where a docker run image argument belongs.
A short list of flags is modelled. Anything else — --privileged, --cap-add, --entrypoint, a --mount with its own syntax — is refused rather than guessed. The translation is one service, not a whole stack.
How to use it
Paste the command into the docker run command box, or press Run with the example already there.
Read the Compose service below: one service named after --name, or app when the flag is absent.
Check the quoted lists in the Compose service — a port or a volume with a colon is quoted so YAML reads it as one string.
Worked example
Input:
docker run -d --name web -p 8080:80 -e MODE=dev -v ./site:/usr/share/nginx/html --restart unless-stopped nginx:latest
Output:
services:
web:
image: nginx:latest
ports:
- "8080:80"
environment:
- "MODE=dev"
volumes:
- "./site:/usr/share/nginx/html"
restart: unless-stopped
Why it runs in your browser
The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.
A Compose service that says the same thing as your `docker run`: the flags become keys, the image becomes `image`, and anything after the image becomes `command`.
A flag this page does not model is refused by name, because dropping `--privileged` would produce a Compose file that quietly runs differently.
What it does, and what it does not
The command is tokenised and walked: `-d` is Compose's default and disappears, `--name` names the service (defaulting to `app`), and `-p`, `-e`, `-v`, `--restart` and `--network` become their Compose keys. Ports, environment entries and volumes are quoted so a colon in a value stays a value.
Everything after the image is joined back into `command`, which is where a `docker run` image argument belongs.
A short list of flags is modelled. Anything else — `--privileged`, `--cap-add`, `--entrypoint`, a `--mount` with its own syntax — is refused rather than guessed. The translation is one service, not a whole stack.
How to use docker run to docker compose
Paste the command into the docker run command box, or press Run with the example already there.
Read the Compose service below: one service named after `--name`, or `app` when the flag is absent.
Check the quoted lists in the Compose service — a port or a volume with a colon is quoted so YAML reads it as one string.
What to Expect
Best for
- Moving a working docker run command into a Compose file
- Seeing how a flag maps to a Compose key
Not ideal for
- A command that uses flags outside the modelled list
- A multi-container stack, which needs more than one command
What this tool keeps
- The image exactly as written, tag included
- Everything after the image as the command
What may need cleanup
- Add healthchecks and networks by hand
- A `--mount` needs rewriting as `volumes:`
Common errors
- The page refuses it: --privileged is not modelled by this page
Example use cases
- Converting a run command from documentation
- Starting a Compose file from a one-liner
Sample input
docker run command: docker run -d --name web -p 8080:80 -e MODE=dev -v ./site:/usr/share/nginx/html --restart unless-stopped nginx:latest
Sample output
Compose service: services: …
Who this is for
- Developers moving to Compose
- Anyone documenting a container's flags
Frequently asked questions
Why is `-d` not in the output?
Compose runs services detached by default, so a detach key would be noise. The flag is accepted and dropped, and the page says so.
What happens to the command after the image?
It becomes command:, joined with spaces. That is where a docker run image argument belongs, and Compose accepts the same string.
Why refuse an unknown flag?
Dropping --privileged or --cap-add would produce a Compose file that looks equivalent and is not. The page names the flag instead.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.