Docker Run to Compose Converter

Turn docker run commands into a Compose file, or a Compose file into docker run commands.

About Docker Run to Compose Converter

Convert docker run commands into a compose.yaml file, or turn each service in a Compose file back into a docker run command, in your browser.

How to use

  1. Paste one or more docker run commands, or a Compose file. The direction is detected from the text; use the switch above the input to set it by hand.
  2. Read the note under the output. It names every option that was not converted and anything that has no equivalent on the other side.
  3. Copy the result or download it. You can also load a .sh or .yaml file.

What it does

  • Splits each command the way bash would: single and double quotes,
    #39;…'
    strings and backslash line continuations. A leading $ prompt and sudo are skipped, and && or ; separate commands. Each docker run becomes one service, named after --name or the image.
  • Converts --name, -p (including 127.0.0.1:8080:80/tcp and port ranges), -v and --mount (bind, named volume and tmpfs), -e, --env-file, --restart, --network, --hostname, -w, -u, --entrypoint, --cap-add, --cap-drop, --device, --privileged, --label, --log-driver, --log-opt, the --health-* options, --add-host, --dns, --shm-size, --ulimit, --tmpfs, --init, -i and -t, plus the image, the command and its arguments.
  • --gpus becomes a device reservation under deploy.resources.reservations.devices with the nvidia driver; -m and --cpus become deploy.resources.limits.
  • Named volumes are also declared under a top-level volumes: key. A network other than host, none or bridge is declared external: true, because docker run expects it to exist already; --network host becomes network_mode: host.
  • A $VAR that the shell would have expanded stays a variable, which Compose fills in from the environment or a .env file. A literal $, such as one inside single quotes, is written $. $(pwd) or $PWD at the start of a volume path becomes ., since Compose reads relative paths from the file's folder.
  • The output follows the Compose Specification used by docker compose, so it has no version: key. Ports are always quoted.
  • Going the other way, each service becomes one docker run -d command, named after container_name or the service. Relative bind paths become $PWD/…, and values holding ${VAR} are put in double quotes so the shell fills them in as Compose would.
  • It does not convert options with no Compose key, such as -P, --stop-timeout or --network-alias; they are listed instead. -d and --rm have no Compose key either: docker compose up -d and docker compose down do those jobs. From Compose it does not convert build, depends_on, profiles, secrets or deploy.replicas; the note says what to do for each, such as running docker build first or starting dependencies in order. It does not read .env files or check options against your Docker version.

Example

docker run -d --name db -e POSTGRES_PASSWORD=example -p 5432:5432 -v pgdata:/var/lib/postgresql/data postgres:16
→
services:
  db:
    image: postgres:16
    container_name: db
    environment:
      POSTGRES_PASSWORD: example
    ports:
      - "5432:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
volumes:
  pgdata:

Privacy

Commands and Compose files are converted in the browser. Nothing is uploaded and nothing is run, so passwords passed with -e stay on this page.

Frequently asked questions

How do I convert a docker run command to docker compose?
Each docker run becomes one service under services:. The image goes in image:, -p in ports:, -v in volumes:, -e in environment: and --restart in restart:. Named volumes also need a top-level volumes: entry. Paste the command above and the file is written for you.
How do I turn a docker-compose.yml back into docker run commands?
Write one docker run per service, turning ports into -p, volumes into -v, environment into -e and the service command into arguments after the image. depends_on and build have no docker run equivalent, so start dependencies first and build images with docker build.
Do I still need the version key in docker-compose.yml?
No. Docker Compose v2 follows the Compose Specification, which ignores the top-level version: key, and recent releases warn that it is obsolete. A file that starts with services: is enough.
How do I use --gpus all in docker compose?
Add a device reservation to the service: deploy.resources.reservations.devices with driver: nvidia, count: all and capabilities: [gpu]. Use device_ids instead of count to pick specific GPUs.