Tools › Developer
docker run to Compose
Paste one or more docker run commands and get the compose.yaml that runs the same containers: ports, volumes, environment, networks, limits and health checks.
About this tool What it's for, how to use it and an example
What it's for
Turn docker run commands into a Compose file, so a container you start by hand can be started, stopped and
updated with docker compose up -d, and its settings live in a file you can keep.
For example, when a project’s README says to run a long docker run -d -p … -v … -e … command, paste it here and
save the result as compose.yaml.
How to use it
Paste one or more docker run (or docker container run) commands, on separate lines or joined with && or
;. Each becomes a service, named after --name or else the image. Lines can be continued with \.
Ports, volumes and mounts, environment variables and env files, labels, restart policy, networks, user, working
directory, hostname, entrypoint, capabilities, devices, DNS, extra hosts, memory and CPU limits, ulimits, logging,
health checks, GPUs, -i and -t, --privileged, --init, --read-only and more all map to their Compose
keys, and anything after the image becomes the command. Port mappings are quoted, as Docker recommends. A named volume (-v data:/path) is also declared at
the top level, and a user-defined network is declared as external, since docker run expects it to exist
already. The message line lists options that have no Compose equivalent (such as --rm). Copy a link to this
input keeps the commands.
Example
Choose Try an example, which pastes an nginx command with a port, two volumes, a time zone and a restart policy. You get:
services:
web:
image: nginx:1.27
container_name: web
ports:
- "8080:80"
volumes:
- data:/var/lib/data
- ./site:/usr/share/nginx/html:ro
environment:
TZ: Europe/London
restart: unless-stopped
volumes:
data: {}
Good to know
Shell variables ($PWD, ${HOME}) are kept as written; Compose fills in ${…} from the environment too, but
$(pwd) it doesn’t, so use . instead. Only docker run is read; docker network create and docker volume
create lines are skipped. Rare options without a Compose key are listed rather than guessed.
Private: this tool runs in your browser. Nothing you type, paste or choose leaves this page.
Saved you a few minutes? Say thanks with a coffee.
Something wrong with this tool, or missing from it? Report a bug or suggest a feature.