Docker Run to Compose Converter
Turn docker run commands into a Compose file, or a Compose file into docker run commands.
About Docker Run to Compose Converter
Convert docker run commands into a compose.yaml file, or turn each service in a Compose file back into a docker run command, in your browser.
How to use
- Paste one or more
docker runcommands, or a Compose file. The direction is detected from the text; use the switch above the input to set it by hand. - Read the note under the output. It names every option that was not converted and anything that has no equivalent on the other side.
- Copy the result or download it. You can also load a
.shor.yamlfile.
What it does
- Splits each command the way bash would: single and double quotes,
#39;…'strings and backslash line continuations. A leading$prompt andsudoare skipped, and&∨separate commands. Eachdocker runbecomes one service, named after--nameor the image. - Converts
--name,-p(including127.0.0.1:8080:80/tcpand port ranges),-vand--mount(bind, named volume and tmpfs),-e,--env-file,--restart,--network,--hostname,-w,-u,--entrypoint,--cap-add,--cap-drop,--device,--privileged,--label,--log-driver,--log-opt, the--health-*options,--add-host,--dns,--shm-size,--ulimit,--tmpfs,--init,-iand-t, plus the image, the command and its arguments. --gpusbecomes a device reservation underdeploy.resources.reservations.deviceswith thenvidiadriver;-mand--cpusbecomedeploy.resources.limits.- Named volumes are also declared under a top-level
volumes:key. A network other thanhost,noneorbridgeis declaredexternal: true, because docker run expects it to exist already;--network hostbecomesnetwork_mode: host. - A
$VARthat the shell would have expanded stays a variable, which Compose fills in from the environment or a.envfile. A literal$, such as one inside single quotes, is written$.$(pwd)or$PWDat the start of a volume path becomes., since Compose reads relative paths from the file's folder. - The output follows the Compose Specification used by
docker compose, so it has noversion:key. Ports are always quoted. - Going the other way, each service becomes one
docker run -dcommand, named aftercontainer_nameor the service. Relative bind paths become$PWD/…, and values holding${VAR}are put in double quotes so the shell fills them in as Compose would. - It does not convert options with no Compose key, such as
-P,--stop-timeoutor--network-alias; they are listed instead.-dand--rmhave no Compose key either:docker compose up -danddocker compose downdo those jobs. From Compose it does not convertbuild,depends_on,profiles,secretsordeploy.replicas; the note says what to do for each, such as runningdocker buildfirst or starting dependencies in order. It does not read.envfiles or check options against your Docker version.
Example
docker run -d --name db -e POSTGRES_PASSWORD=example -p 5432:5432 -v pgdata:/var/lib/postgresql/data postgres:16
→
services:
db:
image: postgres:16
container_name: db
environment:
POSTGRES_PASSWORD: example
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
Privacy
Commands and Compose files are converted in the browser. Nothing is uploaded and nothing is run, so passwords passed with -e stay on this page.
Frequently asked questions
- How do I convert a docker run command to docker compose?
- Each docker run becomes one service under services:. The image goes in image:, -p in ports:, -v in volumes:, -e in environment: and --restart in restart:. Named volumes also need a top-level volumes: entry. Paste the command above and the file is written for you.
- How do I turn a docker-compose.yml back into docker run commands?
- Write one docker run per service, turning ports into -p, volumes into -v, environment into -e and the service command into arguments after the image. depends_on and build have no docker run equivalent, so start dependencies first and build images with docker build.
- Do I still need the version key in docker-compose.yml?
- No. Docker Compose v2 follows the Compose Specification, which ignores the top-level version: key, and recent releases warn that it is obsolete. A file that starts with services: is enough.
- How do I use --gpus all in docker compose?
- Add a device reservation to the service: deploy.resources.reservations.devices with driver: nvidia, count: all and capabilities: [gpu]. Use device_ids instead of count to pick specific GPUs.