Skip to main content

Docker Run to Docker Compose Converter

Paste a docker run command, including multi-line commands with backslashes, and get the equivalent compose.yaml service. Flags it can't convert are listed, not silently dropped.

Free, no signup. Runs entirely in your browser; nothing you enter is sent anywhere.

Supports -p, -e, --env-file, -v, --name, --restart, --network, -w, -u, --entrypoint, labels, caps, resource limits, health checks and more. Unsupported flags are listed, never dropped silently.

compose.yaml
services:
  web:
    image: nginx:1.27
    container_name: web
    restart: unless-stopped
    ports:
      - "8080:80"
    environment:
      - "NODE_ENV=production"
    volumes:
      - data:/var/lib/app
      - ./conf:/etc/app:ro

volumes:
  data:

Run it with docker compose up -d.

Why move a docker run command into Compose

A long docker run line lives in someone's shell history. A compose.yaml lives in Git, gets reviewed, and recreates the same container with docker compose up -d. It also declares named volumes and networks explicitly, so a restart doesn't quietly create an empty volume with a typo in its name.

Two flags behave differently: --rm has no Compose equivalent, and --network host becomes network_mode: host. Networks you join with --network are marked external, because docker run only joins networks that already exist. If the converted file fails to start, check common Docker Compose errors.

Questions people ask

How do I convert docker run to docker compose?

Map each flag to its Compose key: -p to ports, -e to environment, -v to volumes, --name to container_name, --restart to restart and --network to networks, then put the image under the service. This tool does that mapping automatically and lists any flag it can't convert.

What is the Compose equivalent of docker run -d?

There isn't a key for it. Detached mode is chosen when you start the stack: run docker compose up -d. Likewise -it maps to stdin_open: true and tty: true.

Should I use docker-compose.yml or compose.yaml?

Both work. compose.yaml is the current preferred file name in the Compose specification, and docker compose finds it automatically. Older tooling may still look for docker-compose.yml.