Docker Run to Compose Converter
Convert docker run commands to a docker-compose.yml with ports, volumes, env, networks, health checks and GPUs, or turn a compose file back into docker run commands.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the Docker Run to Compose Converter?
Paste one or more docker run commands, as copied from a README or your shell history, and this converter writes the equivalent Compose file. It understands quoting, backslash line continuations, combined flags such as -dit, --flag=value and -p8080:80, and maps more than 60 options to Compose keys: ports, named and bind volumes, --mount, environment variables and env files, networks and aliases, restart policies, health checks, user and working directory, memory and CPU limits, ulimits, logging, capabilities, devices and NVIDIA GPUs. Several commands become several services in one file, with named volumes and networks declared at the top level.
It also works in reverse. Paste a compose.yaml and you get the docker run commands that create the same containers, including docker network create and docker volume create lines that use Compose's project-prefixed names, so data in volumes is shared with docker compose up. Anything that has no direct equivalent, such as --rm, -P or depends_on, is listed as a warning instead of being silently dropped.
- Shell-accurate parsing of quotes, line continuations and combined flags
- More than 60 docker run options mapped to Compose keys
- Multiple commands become multiple services, with top-level volumes and networks
- Reverse conversion with project-prefixed volume and network names
- Warnings for flags with no equivalent
- Copy or download; runs in the browser with the yaml library
How to use the Docker Run to Compose Converter
- Choose "docker run → Compose" and paste one or more commands; separate them with new lines, ; or &&.
- Read the generated file and the warnings for flags that were dropped or need a decision.
- Copy the YAML or download it as compose.yaml, then run docker compose up -d in that folder.
- To go the other way, choose "Compose → docker run", paste the file and set the project name used for volume and network prefixes.
- Use "Use output as input" to flip the result into the other direction and check the round trip.
Worked examples
Postgres with a volume
Input
docker run -d --name db -e POSTGRES_PASSWORD=change-me -v pgdata:/var/lib/postgresql/data -p 5432:5432 --restart unless-stopped postgres:16
Output
services.db with image, container_name, environment, ports, volumes and restart; top-level volumes: pgdata
pgdata has no slash, so it is a named volume and is declared at the top level.
Interactive GPU container
Input
docker run -it --gpus all -v ./models:/models pytorch/pytorch python
Output
stdin_open: true, tty: true, deploy.resources.reservations.devices: [driver nvidia, count all, capabilities [gpu]]
This is the Compose form that the NVIDIA Container Toolkit reads.
Throwaway container
Input
docker run --rm -p8080:80 nginx:alpine
Output
service nginx with ports 8080:80, plus a warning about --rm
The service is named after the image because there is no --name.
Compose back to docker run
Input
A redis service with volume data and ports 6379:6379, project shop
Output
docker network create shop_default; docker volume create shop_data; docker run -d --name redis ... -v shop_data:/data --network shop_default --network-alias redis redis:7-alpine
Using the same names means the container sees the data Compose already stored.
Background and insight
Docker Compose files follow the Compose Specification, which merged the old version 2 and version 3 formats. Docker Compose v2 ignores the top-level version key and prints a warning that it is obsolete, so this converter leaves it out. Service names become DNS names on the project network, which is why services can reach each other as db or redis without links. Compose also prefixes the resources it creates with the project name, usually the folder name: a volume called pgdata in a project called shop is really shop_pgdata.
Most docker run flags map one to one: -p to ports, -e to environment, -v to volumes, --restart to restart, -w to working_dir, -u to user, -m to mem_limit, --health-cmd to healthcheck.test with CMD-SHELL. Some need translation. -i and -t become stdin_open and tty. --gpus all becomes a device reservation under deploy.resources.reservations.devices with driver nvidia and capabilities [gpu]. --network host becomes network_mode: host, while a user-defined network becomes a networks entry, marked external because a docker run command expects it to exist already. A -v whose source is a plain name is a named volume and must be declared under the top-level volumes key; a source starting with / or . is a bind mount.
A few flags have no Compose meaning. --rm removes a container when it exits, but Compose removes containers with docker compose down instead. -P publishes every exposed port to a random host port. -d is how docker compose up -d runs anyway. In the reverse direction, depends_on, profiles and build sections have no docker run equivalent and are reported.
Common use cases
Turning README commands into a stack
Collect the docker run lines from several projects' docs into one Compose file you can version.
Home lab and self-hosting
Move containers started by hand on a NAS or Raspberry Pi into a compose file that survives reboots.
Debugging a Compose service
Get the exact docker run command for one service to start it by hand with different flags.
Writing documentation
Offer readers both a one-line docker run and a compose snippet that stay in sync.
Tips and limitations
- Do not commit real passwords from -e flags; move them to an env_file or Docker secrets and add the file to .gitignore.
- Relative bind mounts such as ./data are resolved from the compose file's folder, not your shell's current directory.
- Replace container_name with nothing if you want to scale a service; fixed names cannot have more than one replica.
- Pin image tags (postgres:16.4) instead of latest so docker compose pull does not upgrade you by surprise.
- Mark networks external only if something else creates them; otherwise remove "external: true" and let Compose create them.
Frequently asked questions
What is the docker compose equivalent of --rm?
There is no service key for it. docker compose down stops and removes the containers of a project. For a one-off command, docker compose run --rm <service> exists and removes the container after it exits.
How do I write docker run -it in a compose file?
Use stdin_open: true for -i and tty: true for -t. Then attach with docker compose attach <service> or open a shell with docker compose exec <service> sh.
How do I give a compose service access to all GPUs?
Add deploy.resources.reservations.devices with driver: nvidia, count: all and capabilities: [gpu]. It is the Compose form of docker run --gpus all and needs the NVIDIA Container Toolkit on the host.
Do I still need the version key at the top of docker-compose.yml?
No. Docker Compose v2 follows the Compose Specification, ignores version and warns that it is obsolete. Start the file with services: instead.
Why does my converted compose file mark the network as external?
Because a docker run --network flag only joins a network that already exists. If you want Compose to create the network, delete "external: true" and it will be created as <project>_<name>.
Can I convert docker-compose.yml back to docker run commands?
Yes. Switch the direction, paste the file and set the project name. The output includes network and volume create commands with Compose-style names, then one docker run per service. Build sections and depends_on are reported because docker run cannot express them.
Is there an in-depth guide to the Docker Run to Compose Converter?
Yes. “From docker run to Docker Compose: Every Flag Mapped” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
People also search for
- convert docker run command to docker compose
- docker compose equivalent of --rm
- docker run -it in docker compose
- docker compose gpus all equivalent
- docker compose version key obsolete warning
- convert docker compose to docker run command
- docker run --restart unless-stopped in compose
- named volume vs bind mount in compose file
Related Tools You May Like
Free, in-browser tools that pair well with this one.