curly{bits}

curlybits / Docker Run to Compose

Docker Run to Docker Compose Converter

Paste one or more docker run commands and get a compose.yaml you can start with docker compose up -d. Ports, volumes and bind mounts, environment variables, networks, restart policies, resource limits, healthchecks, logging and GPU access are all converted, and named volumes and networks are declared for you.

docker run command(s)
compose.yaml

      

How to use the Docker Run to Docker Compose Converter

  1. Paste your docker run command. Put several commands on separate lines to get one service each.
  2. Choose how to write Environment variables, and whether your networks already exist.
  3. Read the notes under the result for any flags that have no Compose equivalent.
  4. Click Download to save compose.yaml, or Copy, then run docker compose up -d in the same folder.

docker run flags and their Compose keys

docker runcompose.yaml
--name webservice name and container_name: web
-p 8080:80ports: ["8080:80"]
-v data:/var/lib/data, --mountvolumes: (named volumes are also declared at the top level)
-e KEY=value, --env-fileenvironment:, env_file:
--restart unless-stoppedrestart: unless-stopped
--network app-net, --network hostnetworks:, network_mode: host
--memory 512m --cpus 1.5mem_limit: 512m, cpus: 1.5
--health-cmd …healthcheck: with test: ["CMD-SHELL", …]
--gpus alldeploy.resources.reservations.devices
-itstdin_open: true, tty: true
Arguments after the imagecommand:

Flags that don't carry over

  • -d: not needed. Use docker compose up -d to start in the background.
  • --rm: services are meant to stay; use docker compose run --rm for 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

Add this docker run to Docker Compose converter to your website

Free for blogs, schools and businesses. Copy the code below and paste it into your page's HTML. The tool works exactly like this one and runs in your visitors' browsers, so nothing is uploaded. Please keep the credit line so others can find it too.

Preview embed ↗