FormatterHQ

Docker Run to Docker Compose Converter

Paste one or more docker run commands and get a ready-to-use compose.yaml with services, named volumes, networks, healthchecks and resource limits.

Input SHELL
Output YAML
Ready.

How to use the Docker Run to Docker Compose

  1. Paste one or more docker run commands. Backslash line continuations and a leading $ or sudo are fine.
  2. Optionally tick Environment as key: value map or choose a version: key.
  3. The YAML is generated automatically; click Convert after editing.
  4. Read the # comments at the top for flags that have no Compose equivalent.
  5. Save the result as compose.yaml and start it with docker compose up -d.

Convert docker run to Docker Compose

This docker run to Docker Compose converter reads the flags of one or more docker run commands and writes the matching services: entries in a compose.yaml file. It is useful when a README only shows long run commands, when you want to version your container setup in Git, or when several containers that you start by hand should come up together with one docker compose up.

Why move from docker run to Compose?

A docker run command is easy to paste but hard to maintain: flags get lost in shell history and it is unclear which containers belong together. A Compose file describes the same settings declaratively. Compose also creates a default network, so services reach each other by service name, and it manages named volumes for you.

Example

Input:

docker run --rm -it -p 3000:3000 --network appnet --network-alias api \
  --env-file .env -m 512m --cpus 1.5 myorg/api:2.1 npm start

Output:

# --rm has no Compose equivalent (use `docker compose run --rm`).
# Network appnet: Compose creates a new one named <project>_<name>. To reuse one made with docker network create, add "external: true" under it.
services:
  api:
    image: myorg/api:2.1
    stdin_open: true
    tty: true
    ports:
      - "3000:3000"
    networks:
      appnet:
        aliases:
          - api
    env_file:
      - .env
    mem_limit: 512m
    cpus: 1.5
    command:
      - npm
      - start
networks:
  appnet: {}

The service name comes from --name when present, otherwise from the image name (myorg/api:2.1 becomes api). Everything after the image is treated as the command. Paste several commands, one after another, to get several services in the same file.

Supported flags

docker runCompose key
-p, --exposeports (quoted strings), expose
-v, --mountvolumes; named volumes are also declared at the top level
-e, --env-fileenvironment, env_file
--name, --restartcontainer_name, restart
--network, --network-aliasnetworks with aliases, or network_mode for host, none, bridge and container:
--health-cmd, --health-interval, etc.healthcheck with CMD-SHELL
-m, --cpus, --ulimit, --shm-sizemem_limit, cpus, ulimits, shm_size
--gpus alldeploy.resources.reservations.devices with the GPU capability
-it, -w, -u, --entrypointstdin_open, tty, working_dir, user, entrypoint

Labels, capabilities, DNS settings, extra hosts, devices, tmpfs, logging driver and options, sysctls, --privileged, --init, --read-only and --platform are converted too.

Options explained

Environment as key: value map switches environment from a list of KEY=value strings to a YAML mapping, which some teams find easier to read and diff. version: is omitted by default because the current Compose Specification ignores it. Choose 3.8 or 3.9 only if an older tool in your pipeline still requires the key.

Limitations

  • --rm has no Compose equivalent; the tool adds a comment suggesting docker compose run --rm for one-off containers.
  • -P (publish all exposed ports) is dropped, because Compose needs explicit port mappings.
  • --link is converted to links, but this is a legacy feature. On the default Compose network, services can already reach each other by name, so you can usually delete it.
  • -d is ignored; detached mode is chosen at docker compose up -d time.
  • Commands other than docker run or docker create (such as docker build) are skipped and listed in a # Skipped comment; an error appears only when the input has no docker run command at all.
  • A named volume or network gets a comment: Compose creates a new one prefixed with the project name, so add external: true to reuse one that already exists.
  • $(pwd) at the start of a host path becomes ., and a $ that the shell would pass on literally (single-quoted or escaped) is written $$, the Compose escape.

Ports are always written as quoted strings. That avoids a classic YAML 1.1 pitfall where an unquoted value like 22:22 can be read as a base-60 number.

Privacy

The conversion happens in your browser, so passwords in -e flags are never uploaded. Still, consider moving secrets into an .env file before committing the YAML. To check or tidy the result, use the YAML validator or YAML formatter, and convert an env file to structured data with ENV to YAML.

Frequently asked questions

Can I convert several docker run commands into one Compose file?
Yes. Paste them one after another, on separate lines or joined with &&. Each command becomes its own service, and shared named volumes and networks are declared once at the top level.
Do I still need the version key in docker-compose.yml?
No. Docker Compose v2 follows the Compose Specification, which treats version as obsolete and prints a warning when it is present. The converter omits it unless you pick 3.8 or 3.9.
Why is --rm missing from the output?
Compose manages container lifecycles itself, so there is no rm key. For throwaway containers, run docker compose run --rm service instead.
How are bind mounts told apart from named volumes?
A source that starts with ., /, ~, $ or a Windows drive letter is treated as a host path. Anything else, such as pgdata, is a named volume and is also listed under the top-level volumes: key.
Is this the same as composerize?
It solves the same problem. This converter runs entirely in your browser, handles several commands at once, and adds comments for flags it cannot represent instead of dropping them silently.

Last updated October 3, 2026

Guides

Related tools

File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used. JWT Decoder Decode a JSON Web Token to inspect its header, payload claims and expiry time, and verify its signature with your key. Runs locally. JWT Encoder & Generator Create and sign JSON Web Tokens with HS256, RS256, ES256, PS256 or EdDSA using a secret or PEM key. Signing happens in your browser. JWT Verifier Verify a JWT signature with a shared secret, PEM public key, X.509 certificate or JWKS and check exp, nbf, iss and aud claims. MIME Type Lookup Find the MIME / Content-Type for a file extension or the extensions for a media type — about 150 common types. MongoDB ObjectId to Timestamp Extract the creation date from MongoDB ObjectIds and see the random and counter parts; also builds a date-range _id query. QR Code Generator Create free QR codes for URLs, text, Wi-Fi, vCards, e-mail, SMS, phone numbers, locations and events. Custom colours, PNG and SVG. QR Code Reader & Scanner Scan QR codes from an image, screenshot or your camera and see the content — links, Wi-Fi passwords, contacts — safely before opening. Regex Cheat Sheet Interactive regex cheat sheet: anchors, classes, quantifiers, groups, lookarounds, flags and Unicode, with clickable examples and a flavour table. Regex Escape Escape special characters so any text can be matched literally inside a regular expression in JavaScript, PCRE, Python or Java. Regex Explainer Break a regular expression into tokens and explain each part in plain English: groups, quantifiers, classes, anchors and lookarounds.