DevKit
Converter

Docker Run to Compose

Convert docker run commands to docker-compose.yml format.

Last updated: August 2026

Share:

Was this tool helpful?

From a run command to a compose file

This tool translates a docker run command, with all its flags, into the equivalent docker-compose.yml service. Ports, volumes, environment variables, the restart policy, and the image name each map to a key under the service, so a one-off command you have been pasting into a terminal becomes a declarative file you can commit and reuse.

When you reach for it

Useful when a project's README documents only a long docker run line and you want it version-controlled, when combining several containers that must talk to each other, or when moving from ad-hoc commands to a reproducible local stack.

Example

# docker run
docker run -d --name db \
  -p 5432:5432 \
  -e POSTGRES_PASSWORD=secret \
  -v pgdata:/var/lib/postgresql/data \
  postgres:16

# docker-compose.yml
services:
  db:
    image: postgres:16
    ports:
      - "5432:5432"
    environment:
      POSTGRES_PASSWORD: secret
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Common pitfalls

Named volumes need a top-level volumes: declaration or Compose errors out, which the run command never required. The port mapping order also matters: in "5432:5432" the host port is on the left and the container port on the right, and swapping them silently binds the wrong port. Quote any mapping where the host port is omitted, like ":80", so YAML does not misread the colon. One more: --link has no direct Compose equivalent; containers on the same Compose network already reach each other by service name, so drop the link entirely.

FAQ

Why does Compose complain about my volume? A named volume must also appear under the top-level volumes: key. Bind mounts with a host path do not.

How do containers reach each other? By service name on the shared network. The db service is reachable at the host db from other services.

Do I keep --name? Compose derives container names from the service, so an explicit name is optional and often omitted.