docker run to Docker Compose converter

Paste one or more docker run commands and get a compose.yaml with every flag explained. Quotes, escapes, line continuations and combined short flags such as -dit are split the way a shell would split them. Free, anonymous and converted in your browser.

Convert docker run commands

One service per docker run or docker create. Separate commands with new lines, ; or &&. Other commands, such as docker network create, are skipped.

1 service, 1 named volume, 1 warning.

Review before you run it

  • Warning: Secret-looking values (POSTGRES_PASSWORD) would be stored in plain text in compose.yaml. Move them to an env_file kept out of version control, use Compose secrets, or turn on “Replace secret-looking values”.
  • Note: Not part of a Compose file: -d. See the mapping table for the matching docker compose command.

How each flag was mapped

Service db from postgres:16
docker runComposeWhy
-d—Not a Compose file setting. Run docker compose up -d to start in the background.
--name dbcontainer_name (+ service name)Also used as the service key. A fixed container_name prevents scaling the service beyond one container.
--restart unless-stoppedrestartQuoted because YAML 1.1 reads a bare no as false.
-e POSTGRES_USER=appenvironment.POSTGRES_USERValues are quoted so YAML keeps them as text.
-e POSTGRES_DB=appenvironment.POSTGRES_DBValues are quoted so YAML keeps them as text.
-e POSTGRES_PASSWORD=••••••environment.POSTGRES_PASSWORDValues are quoted so YAML keeps them as text.
-v pgdata:/var/lib/postgresql/datavolumes + top-level volumesNamed volume. It is declared at the top level with name: pgdata so Compose reuses the volume docker run created instead of a project-prefixed one.
-p 127.0.0.1:5432:5432portsQuoted so YAML never reads it as a number or base-60 value.
--health-cmd pg_isready -U apphealthcheck.testdocker run runs the health command in a shell, so it becomes CMD-SHELL.
--health-interval 10shealthcheck.intervalTime between checks.
--health-retries 5healthcheck.retriesConsecutive failures before unhealthy.

What the converter understands

  • Single and double quotes, backslash escapes, and line continuations written as \ (bash), ` (PowerShell) or ^ (cmd.exe). A backslash before a letter or digit is kept, so Windows paths such as C:\data survive.
  • Flag values written as --name=db, --name db, -p8080:80 or inside combined short flags such as -dit.
  • Several commands at once. Each docker run becomes a service named after --name or the image, and --network, --link, --volumes-from and container: references point at the other pasted services.
  • Everything after the image becomes an exec-form command list, because docker run passes those words to the container as separate arguments.

Volumes, networks and paths

Compose prefixes volumes it creates with the project name. A named volume from -v pgdata:/data is therefore declared with name: pgdata, so the file keeps using the volume that docker run created. Remove the name line if you want a fresh, project-scoped volume.

A custom --network must already exist for docker run, so it is declared external: true; Compose then expects it to exist and will not create it. host, none, bridge and container:<name> become network_mode. Relative bind paths, and $(pwd) rewritten to ., resolve from the folder that holds compose.yaml.

Flags without a Compose equivalent

-d, --rm and -a describe how the docker CLI runs a container, not the container itself. Use docker compose up -d to start in the background and docker compose run --rm SERVICE for one-off containers. -P has no Compose equivalent, so list each port under ports. These flags are listed in the notes instead of being dropped silently, and unrecognized flags produce a visible warning.

Keep secrets out of compose.yaml

Values for variables named like passwords, tokens or keys, and URLs with an embedded password, trigger a warning without being repeated in it. The option above writes ${NAME} references, which Compose interpolates from your shell or a .env file. For stronger isolation, use env_file or Compose secrets, which are mounted as files under /run/secrets/; environment variables can reach every process and debugging logs.

Flag reference

Every docker run flag this page recognizes and what it becomes. Attribute names follow the Compose file services reference and flag behavior follows the docker container run reference. The output omits the obsolete top-level version element.

docker run flag Compose Notes
--namecontainer_name (+ service name)Also used as the service key. A fixed container_name prevents scaling the service beyond one container.
--platformplatformImage platform, such as linux/arm64.
--pullpull_policySame values: missing, always or never.
--entrypointentrypointWritten as a one-item list: docker run treats the value as a single executable, not a shell line.
-w, --workdirworking_dirOverrides the image working directory.
-u, --useruserUser or UID[:GID] for the container process.
-h, --hostnamehostnameContainer hostname.
--domainnamedomainnameContainer domain name.
--restartrestartQuoted because YAML 1.1 reads a bare no as false.
-p, --publishportsQuoted so YAML never reads it as a number or base-60 value.
--exposeexposeDocuments a container port without publishing it on the host.
-e, --envenvironment.KEYValues are quoted so YAML keeps them as text.
--env-fileenv_fileCompose resolves the path from the compose.yaml folder, not your shell directory.
-v, --volumevolumes + top-level volumesNamed volume. It is declared at the top level with name: data so Compose reuses the volume docker run created instead of a project-prefixed one.
--mountvolumes (long syntax)Volume mount in long syntax; named volumes are also declared at the top level.
--tmpfstmpfsIn-memory mount. The Compose reference documents mode, uid and gid options; check others with docker compose config.
--volumes-fromvolumes_fromPoints at a pasted service when the container name matches, otherwise at container:<name>.
--network, --netnetworks or network_modehost, none, bridge and container:<name> become network_mode; other names join an existing network.
--network-alias, --net-aliasnetworks.<name>.aliasesExtra DNS name on that network.
--ipnetworks.<name>.ipv4_addressNeeds a user-defined network with a matching subnet.
--ip6networks.<name>.ipv6_addressNeeds a user-defined IPv6 network.
--add-hostextra_hostsWritten as host=ip, the separator Compose prefers (Compose 2.24.1 or newer).
--dnsdnsCustom DNS server.
--dns-searchdns_searchDNS search domain.
--dns-option, --dns-optdns_optResolver option.
--linklinksLegacy feature. Services on the same Compose network already reach each other by service name.
--mac-addressmac_addressSome runtimes require networks.<name>.mac_address instead.
-l, --labellabels.keyContainer label; a bare key gets an empty value.
--label-filelabel_fileFile of key=value labels.
--log-driverlogging.driverLogging driver; available drivers depend on the platform.
--log-optlogging.options.max-sizeDriver-specific logging option.
--cap-addcap_addAdds a Linux capability.
--cap-dropcap_dropDrops a Linux capability.
--privilegedprivileged: trueElevated privileges. Prefer specific cap_add entries where possible.
--security-optsecurity_optSecurity option such as no-new-privileges:true.
--devicedevicesHOST_PATH:CONTAINER_PATH[:permissions].
--gpusgpusRequests all GPUs.
--group-addgroup_addAdditional group.
--read-onlyread_only: trueRead-only root filesystem; add tmpfs or volumes for writable paths.
--sysctlsysctls.net.core.somaxconnNamespaced kernel parameter.
--usernsuserns_modeUser namespace mode.
--pidpidPID namespace mode.
--ipcipcIPC namespace mode.
--utsutsUTS namespace mode.
--runtimeruntimeContainer runtime name.
--cgroup-parentcgroup_parentParent cgroup.
-m, --memorymem_limitHard memory limit (byte value such as 512m).
--memory-reservationmem_reservationSoft memory limit.
--memory-swapmemswap_limitMemory plus swap; -1 means unlimited.
--cpuscpusNumber of CPUs, fractional values allowed.
-c, --cpu-sharescpu_sharesRelative CPU weight.
--cpuset-cpuscpusetAllowed CPUs, such as 0-3 or 0,1.
--pids-limitpids_limitMaximum processes; -1 means unlimited.
--oom-score-adjoom_score_adjOOM killer preference from -1000 to 1000.
--shm-sizeshm_sizeSize of /dev/shm.
--ulimitulimits.nofileA single value sets both soft and hard limits.
-t, --ttytty: trueAllocates a pseudo-TTY.
-i, --interactivestdin_open: trueKeeps STDIN open.
--initinit: trueRuns an init process that forwards signals and reaps zombies.
--stop-signalstop_signalSignal sent to stop the container.
--stop-timeoutstop_grace_periodSeconds become a duration such as 30s.
--health-cmdhealthcheck.testdocker run runs the health command in a shell, so it becomes CMD-SHELL.
--health-intervalhealthcheck.intervalTime between checks.
--health-timeouthealthcheck.timeoutTime a check may take.
--health-retrieshealthcheck.retriesConsecutive failures before unhealthy.
--health-start-periodhealthcheck.start_periodStartup grace period.
--health-start-intervalhealthcheck.start_intervalCheck interval during the start period.
--no-healthcheckhealthcheck.disableDisables the image HEALTHCHECK.
-d, --detach—No Compose equivalent. Not a Compose file setting. Run docker compose up -d to start in the background.
--rm—No Compose equivalent. Compose keeps containers until docker compose down. For one-off containers use docker compose run --rm SERVICE.
-a, --attach—No Compose equivalent. Stream attachment is chosen by the CLI. docker compose up attaches to service output; use docker compose logs or attach later.
-P, --publish-all—No Compose equivalent. No Compose equivalent: list each port explicitly.
--detach-keys—No Compose equivalent. Applies to the docker CLI session only.
--sig-proxy—No Compose equivalent. Applies to the docker CLI session only.
--cidfile—No Compose equivalent. Applies to the docker CLI session only.
-q, --quiet—No Compose equivalent. Applies to the docker CLI session only.
--disable-content-trust—No Compose equivalent. Applies to the docker CLI session only.
--help—No Compose equivalent. Applies to the docker CLI session only.
--annotation—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--blkio-weight—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--blkio-weight-device—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cgroupns—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-count—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-percent—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-period—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-quota—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-rt-period—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpu-rt-runtime—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--cpuset-mems—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--device-cgroup-rule—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--device-read-bps—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--device-read-iops—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--device-write-bps—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--device-write-iops—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--io-maxbandwidth—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--io-maxiops—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--isolation—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--kernel-memory—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--link-local-ip—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--memory-swappiness—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--storage-opt—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--volume-driver—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--oom-kill-disable—Not converted. Not converted automatically. Check the Compose reference for an equivalent.
--use-api-socket—Not converted. Not converted automatically. Check the Compose reference for an equivalent.