Skip to content
OpsAtlas

docker run to Docker Compose converter

Docker

Paste one or more docker run commands and get an equivalent Compose file, with named volumes and networks declared and a note for every flag Compose cannot express.

Runs entirely in your browser — your input is never uploaded.

One command per line. Backslash line continuations, quotes and multiple commands are supported.

compose.yaml

Paste a docker run command or load the sample to see the Compose file.

How the conversion works

The converter reads your command the way a POSIX shell would: quotes, escaped spaces and \ line continuations are honoured, and ;, && or a new line start the next command. Everything between docker run and the image name is treated as an option; everything after the image becomes the service command.

Each option is mapped to its Compose Specification key. Named volumes (a source without a / or .) and user-defined networks are collected and declared once at the top level, so docker compose up works without manual edits.

Example

This command starts a Redis cache with persistence, a memory limit and a healthcheck:

docker run -d --name cache \
  -p 127.0.0.1:6379:6379 \
  -v redis-data:/data \
  --memory 512m \
  --health-cmd "redis-cli ping" --health-interval 10s \
  --restart unless-stopped \
  redis:7.4 redis-server --appendonly yes

It becomes:

services:
  cache:
    image: redis:7.4
    container_name: cache
    ports:
    - "127.0.0.1:6379:6379"
    volumes:
    - redis-data:/data
    mem_limit: 512m
    healthcheck:
      test:
      - CMD-SHELL
      - redis-cli ping
      interval: 10s
    restart: unless-stopped
    command:
    - redis-server
    - --appendonly
    - "yes"
volumes:
  redis-data: {}

Note that yes is quoted: unquoted, a YAML 1.1 parser would turn it into the boolean true and Redis would receive the wrong argument.

Flag mapping reference

docker runcompose.yaml
--namecontainer_name (and the service name)
-p, --publishports
-v, --volume, --mountvolumes (+ top-level volumes for named ones)
-e, --env, --env-fileenvironment, env_file
--networknetworks (or network_mode for host/none)
--restartrestart
--memory, --cpusmem_limit, cpus
--health-*healthcheck
--gpusdeploy.resources.reservations.devices
--log-driver, --log-optlogging
-i, -tstdin_open, tty

Things to check after converting

  • Drop container_name if you want to scale. A fixed container name prevents docker compose up --scale. The service name is enough for DNS between services.
  • Move secrets out of the file. -e PASSWORD=… turns into a plain-text value in compose.yaml. Use an .env file (ignored by git) or Compose secrets instead.
  • Add depends_on yourself. docker run has no ordering, so the converter cannot know that web needs db. Combine depends_on with condition: service_healthy when a healthcheck exists.
  • Pin image versions. The converter warns when an image has no tag or uses latest, because a rebuild can silently pull a different major version.

Frequently asked questions

Does the converter support several docker run commands at once?
Yes. Put each command on its own line (or separate them with ; or &&). Each becomes a service, and named volumes and networks used by any of them are declared once at the top level.
Why are my port mappings quoted in the output?
YAML 1.1 parsers read values like 22:22 as base-60 numbers. Quoting every port mapping is the form recommended by the Compose documentation and avoids that trap.
Which docker run flags have no Compose equivalent?
Flags that control the docker CLI process rather than the container, such as --rm, -a/--attach, --cidfile and -P/--publish-all. The converter lists them as warnings instead of silently dropping them.
Should I keep the version key at the top of the file?
No. The top-level version key is obsolete in the Compose Specification and Docker Compose v2 ignores it with a warning, so the generated file leaves it out.
Is my command sent to a server?
No. Parsing and conversion run in JavaScript in your browser, so environment variables and secrets in the command never leave your machine.
  • Kubernetes YAML validator and visualizer

    Paste Kubernetes manifests to get a resource diagram and a security and best-practice review: privileged pods, root, probes, limits, deprecated APIs.

    KubernetesBeta
  • YAML ⇄ JSON converter

    Convert YAML to JSON and back with exact error positions, anchor and merge-key expansion, and warnings for YAML 1.1 gotchas like the Norway problem.

    Kubernetes
  • CIDR calculator and subnet splitter

    Calculate network, broadcast, host range, netmask and wildcard for any IPv4 CIDR, then split it into subnets by prefix, count or host size.

    Network
  • Dockerfile linter and fixer

    Lint a Dockerfile in your browser: find root users, unpinned images, leaked secrets and bloated layers, then apply safe fixes in one click.

    DockerBeta

Last updated · More Docker tools