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.
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
| docker run | Compose | Why |
|---|---|---|
-d | — | Not a Compose file setting. Run docker compose up -d to start in the background. |
--name db | container_name (+ service name) | Also used as the service key. A fixed container_name prevents scaling the service beyond one container. |
--restart unless-stopped | restart | Quoted because YAML 1.1 reads a bare no as false. |
-e POSTGRES_USER=app | environment.POSTGRES_USER | Values are quoted so YAML keeps them as text. |
-e POSTGRES_DB=app | environment.POSTGRES_DB | Values are quoted so YAML keeps them as text. |
-e POSTGRES_PASSWORD=•••••• | environment.POSTGRES_PASSWORD | Values are quoted so YAML keeps them as text. |
-v pgdata:/var/lib/postgresql/data | volumes + top-level volumes | Named 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:5432 | ports | Quoted so YAML never reads it as a number or base-60 value. |
--health-cmd pg_isready -U app | healthcheck.test | docker run runs the health command in a shell, so it becomes CMD-SHELL. |
--health-interval 10s | healthcheck.interval | Time between checks. |
--health-retries 5 | healthcheck.retries | Consecutive 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 asC:\datasurvive. -
Flag values written as
--name=db,--name db,-p8080:80or inside combined short flags such as-dit. -
Several commands at once. Each
docker runbecomes a service named after--nameor the image, and--network,--link,--volumes-fromandcontainer:references point at the other pasted services. -
Everything after the image becomes an exec-form
commandlist, 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 |
|---|---|---|
--name | container_name (+ service name) | Also used as the service key. A fixed container_name prevents scaling the service beyond one container. |
--platform | platform | Image platform, such as linux/arm64. |
--pull | pull_policy | Same values: missing, always or never. |
--entrypoint | entrypoint | Written as a one-item list: docker run treats the value as a single executable, not a shell line. |
-w, --workdir | working_dir | Overrides the image working directory. |
-u, --user | user | User or UID[:GID] for the container process. |
-h, --hostname | hostname | Container hostname. |
--domainname | domainname | Container domain name. |
--restart | restart | Quoted because YAML 1.1 reads a bare no as false. |
-p, --publish | ports | Quoted so YAML never reads it as a number or base-60 value. |
--expose | expose | Documents a container port without publishing it on the host. |
-e, --env | environment.KEY | Values are quoted so YAML keeps them as text. |
--env-file | env_file | Compose resolves the path from the compose.yaml folder, not your shell directory. |
-v, --volume | volumes + top-level volumes | Named 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. |
--mount | volumes (long syntax) | Volume mount in long syntax; named volumes are also declared at the top level. |
--tmpfs | tmpfs | In-memory mount. The Compose reference documents mode, uid and gid options; check others with docker compose config. |
--volumes-from | volumes_from | Points at a pasted service when the container name matches, otherwise at container:<name>. |
--network, --net | networks or network_mode | host, none, bridge and container:<name> become network_mode; other names join an existing network. |
--network-alias, --net-alias | networks.<name>.aliases | Extra DNS name on that network. |
--ip | networks.<name>.ipv4_address | Needs a user-defined network with a matching subnet. |
--ip6 | networks.<name>.ipv6_address | Needs a user-defined IPv6 network. |
--add-host | extra_hosts | Written as host=ip, the separator Compose prefers (Compose 2.24.1 or newer). |
--dns | dns | Custom DNS server. |
--dns-search | dns_search | DNS search domain. |
--dns-option, --dns-opt | dns_opt | Resolver option. |
--link | links | Legacy feature. Services on the same Compose network already reach each other by service name. |
--mac-address | mac_address | Some runtimes require networks.<name>.mac_address instead. |
-l, --label | labels.key | Container label; a bare key gets an empty value. |
--label-file | label_file | File of key=value labels. |
--log-driver | logging.driver | Logging driver; available drivers depend on the platform. |
--log-opt | logging.options.max-size | Driver-specific logging option. |
--cap-add | cap_add | Adds a Linux capability. |
--cap-drop | cap_drop | Drops a Linux capability. |
--privileged | privileged: true | Elevated privileges. Prefer specific cap_add entries where possible. |
--security-opt | security_opt | Security option such as no-new-privileges:true. |
--device | devices | HOST_PATH:CONTAINER_PATH[:permissions]. |
--gpus | gpus | Requests all GPUs. |
--group-add | group_add | Additional group. |
--read-only | read_only: true | Read-only root filesystem; add tmpfs or volumes for writable paths. |
--sysctl | sysctls.net.core.somaxconn | Namespaced kernel parameter. |
--userns | userns_mode | User namespace mode. |
--pid | pid | PID namespace mode. |
--ipc | ipc | IPC namespace mode. |
--uts | uts | UTS namespace mode. |
--runtime | runtime | Container runtime name. |
--cgroup-parent | cgroup_parent | Parent cgroup. |
-m, --memory | mem_limit | Hard memory limit (byte value such as 512m). |
--memory-reservation | mem_reservation | Soft memory limit. |
--memory-swap | memswap_limit | Memory plus swap; -1 means unlimited. |
--cpus | cpus | Number of CPUs, fractional values allowed. |
-c, --cpu-shares | cpu_shares | Relative CPU weight. |
--cpuset-cpus | cpuset | Allowed CPUs, such as 0-3 or 0,1. |
--pids-limit | pids_limit | Maximum processes; -1 means unlimited. |
--oom-score-adj | oom_score_adj | OOM killer preference from -1000 to 1000. |
--shm-size | shm_size | Size of /dev/shm. |
--ulimit | ulimits.nofile | A single value sets both soft and hard limits. |
-t, --tty | tty: true | Allocates a pseudo-TTY. |
-i, --interactive | stdin_open: true | Keeps STDIN open. |
--init | init: true | Runs an init process that forwards signals and reaps zombies. |
--stop-signal | stop_signal | Signal sent to stop the container. |
--stop-timeout | stop_grace_period | Seconds become a duration such as 30s. |
--health-cmd | healthcheck.test | docker run runs the health command in a shell, so it becomes CMD-SHELL. |
--health-interval | healthcheck.interval | Time between checks. |
--health-timeout | healthcheck.timeout | Time a check may take. |
--health-retries | healthcheck.retries | Consecutive failures before unhealthy. |
--health-start-period | healthcheck.start_period | Startup grace period. |
--health-start-interval | healthcheck.start_interval | Check interval during the start period. |
--no-healthcheck | healthcheck.disable | Disables 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. |