SELFHOST.COMPUTER

Docker Run to Compose

Many project READMEs give you a long docker run command. A Compose file is easier to keep, review and update. Paste the command below and get the same container as a docker-compose.yml. The conversion runs in your browser; nothing is sent anywhere.

The tool converts the common flags and tells you about every flag it can't convert, so nothing disappears silently. Read the result before you run it.

Line breaks with a trailing \ are fine. Start with docker run (sudo and docker container run work too). Don't paste real passwords or tokens into any web page; swap them for placeholders first.

docker-compose.yml


What it converts

  • Basics: --name (container_name), --restart, -p (ports), --expose, -v and --mount (volumes, including bind mounts and read-only), --tmpfs, -e and --env-file, -l (labels), -w, -u, -h, --entrypoint and the command after the image.
  • Network: --network (a named network or host), --add-host, --dns and related, --link.
  • Security: --cap-add, --cap-drop, --privileged, --read-only, --security-opt, --group-add, --device, --sysctl, --ulimit, --init.
  • Resources: --memory, --memory-reservation, --memory-swap, --cpus, --cpu-shares, --cpuset-cpus, --shm-size, --pids-limit, --oom-score-adj.
  • Lifecycle and health: --health-cmd with its interval, timeout, retries and start period, --no-healthcheck, --stop-signal, --stop-timeout, --log-driver and --log-opt, --platform, --pull, -i and -t.

The names on the Compose side come from the Compose Specification; the flags come from the docker run reference.

What it does not convert

  • -d is dropped. You start a Compose project detached with docker compose up -d.
  • --rm has no Compose setting. For a throwaway container use docker compose run --rm <service>.
  • -P (publish all exposed ports) is left out on purpose. List the ports you want under ports:.
  • --network-alias belongs under the network in Compose, so the tool warns instead of guessing.
  • Anything else it doesn't know is listed in a warning above the output. If an unknown flag takes a value, write it as --flag=value so the value isn't read as the image name.

Things to check after converting

  • Named volumes are declared at the bottom of the file. Compose adds the project name (usually the folder name) in front of the real volume name, so a volume called data can become myproject_data. If you want to keep an existing volume, add a name: to it, or the data will look like it vanished.
  • Dollar signs. Compose reads $VAR as a variable. The tool writes a literal $ as $$. Use $VAR yourself only if you want Compose to fill it from the environment or an .env file.
  • Networks. Names given with --network are marked external: true, so they must already exist. Delete that line if Compose should create the network.
  • Port exposure. Docker publishes -p 8080:80 on every interface and bypasses ufw. Read why Docker ignores ufw and bind to 127.0.0.1 or use a reverse proxy where you can.
  • container_name stops Compose from scaling the service to more than one container, according to the specification. Delete it if you don't need a fixed name.

FAQ

Is it safe to paste my command?

The page runs on your device and doesn't send the text anywhere. Still, replace real passwords and tokens with placeholders before pasting into any web page, and put the real values in a .env file. The secret generator makes strong values.

Does the result match docker run exactly?

For the converted flags, yes. One difference is networking: containers started with plain docker run share Docker's default bridge, while Compose creates a project network where services find each other by name. That's usually what you want.

Which Compose version does it target?

The file has no version: line, which the current Compose Specification doesn't use. Check the output with docker compose config, which prints the resolved file or an error.

What next?

Put a reverse proxy in front with the Compose and Caddy generator or the Docker and Caddy guide, cap memory per container (see the swap calculator and RAM budget), and plan updates with updating Docker containers safely.