Skip to main content
Prabhava Groups

Docker Run to Docker Compose Converter

Paste one or more docker run commands and get a clean docker-compose.yml. Anything that has no Compose equivalent is flagged, so nothing is silently dropped.

Line continuations (\), quotes and several commands at once are supported.

docker-compose.yml

What this converter does

Docker Compose describes containers in a YAML file you can commit, review and start with one command. Many projects begin as a long docker run line pasted from a README. This tool translates that line into Compose syntax: the image, container name, published ports, volumes, environment variables, networks, restart policy and the command that follows the image.

How to use it

Paste your command, or choose an example, and the YAML appears instantly. Copy it or download it as docker-compose.yml, then run docker compose up -d in the same folder. Named volumes are declared in a top-level volumes block, and bind mounts written as $(pwd) become . so the file stays portable.

Supported flags

The core set is -p, -v, -e, --name, --restart, --network, -d and the image plus its command. Beyond that the tool maps --env-file, --mount, -u, -w, -h, --entrypoint, --cap-add, --privileged, -m, --cpus, health checks, logging options and --gpus.

Worked example

This command starts a PostgreSQL database that survives restarts:

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

It becomes:

services:
  db:
    image: postgres:16
    container_name: db
    restart: unless-stopped
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_PASSWORD=secret
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata: {}

Common mistakes

  • Unquoted port mappings. YAML can read 22:22 as a base-60 number. The converter always quotes ports, so keep the quotes if you edit them.
  • Flags after the image. Anything after the image name is the container command, not a Docker option. Put -p and friends before the image.
  • Literal dollar signs. Compose substitutes $VARIABLES. Write $$ when you need a real dollar sign in a value.
  • Secrets in the file. Passwords in environment end up in version control. Prefer an env_file that is git-ignored.

Frequently asked questions

Do I need the version key in docker-compose.yml?

No. The top-level version field is obsolete in the Compose Specification and current Docker Compose ignores it with a warning. The converter leaves it out.

Why are my networks marked external?

docker run requires a --network to exist already, so the converter declares it as external: true. Remove that line if you would rather have Compose create the network for you.

What happens to the -d and --rm flags?

Neither belongs in the file. Start the stack in the background with docker compose up -d, and use docker compose run --rm for one-off containers.

Can I convert several docker run commands at once?

Yes. Put each command on its own line, or join them with && or a semicolon. Every command becomes a separate service, and duplicate names get a numeric suffix.

Is my command, including passwords, sent anywhere?

No. The conversion runs entirely in your browser and nothing is uploaded. Even so, move real secrets into an env_file or Docker secrets instead of committing them to a Compose file.