How to use the Docker Run to Docker Compose Converter
- Paste your
docker runcommand. Put several commands on separate lines to get one service each. - Choose how to write Environment variables, and whether your networks already exist.
- Read the notes under the result for any flags that have no Compose equivalent.
- Click Download to save
compose.yaml, or Copy, then rundocker compose up -din the same folder.
docker run flags and their Compose keys
| docker run | compose.yaml |
|---|---|
--name web | service name and container_name: web |
-p 8080:80 | ports: ["8080:80"] |
-v data:/var/lib/data, --mount | volumes: (named volumes are also declared at the top level) |
-e KEY=value, --env-file | environment:, env_file: |
--restart unless-stopped | restart: unless-stopped |
--network app-net, --network host | networks:, network_mode: host |
--memory 512m --cpus 1.5 | mem_limit: 512m, cpus: 1.5 |
--health-cmd … | healthcheck: with test: ["CMD-SHELL", …] |
--gpus all | deploy.resources.reservations.devices |
-it | stdin_open: true, tty: true |
| Arguments after the image | command: |
Flags that don't carry over
-d: not needed. Usedocker compose up -dto start in the background.--rm: services are meant to stay; usedocker compose run --rmfor one-off tasks.-P: publishing every exposed port to a random host port has no Compose key. List the ports you need.
Networks: new or existing?
If you converted every container that shares a network, leave networks already exist off: Compose creates the network for you (named after the project folder) and services reach each other by service name. If other containers outside this file still use the network you created with docker network create, tick it so Compose joins that network with external: true.
No more version: line
Old guides start with version: "3.8". Docker Compose v2 ignores it and warns that it's obsolete, so it's left out. Save the file as compose.yaml (the preferred name) or docker-compose.yml; both are found automatically.
Frequently asked questions
Can I convert several containers at once?
Yes. Paste each docker run command on its own line (lines ending in \ continue the same command). Each becomes a service, and shared named volumes and networks are declared once.
Why are the ports in quotes?
YAML can read values like 22:22 as numbers in base 60. Quoting every port mapping avoids that well-known trap.
Does it convert docker compose back to docker run?
Not yet. This tool converts in one direction, from docker run to Compose.
Can I validate the result?
Run docker compose config in the folder. It checks the file and prints the fully resolved configuration.
Is my command uploaded?
No. It's converted in your browser, so passwords in environment variables stay on your device.
Updated