Home › Tools

Convert docker run to docker compose

Convert one or more docker run commands into a docker compose file. Handles -p, -v, --mount, -e, --env-file, --name, --restart, --network, -w, -u, --entrypoint, healthchecks, --gpus and the image's command, and explains what has no Compose equivalent.

🔒 Runs entirely in your browser. Nothing you paste is uploaded or sent to a server.

How flags map to Compose keys

docker run compose.yaml
--name web container_name: web, and the service is named web
-p 8080:80 ports: ["8080:80"]
-v ./data:/data, -v pgdata:/data volumes:; named volumes are also declared at the top level
--mount type=bind,… long-syntax volume (type, source, target, read_only)
-e KEY=value, --env-file .env environment:, env_file:
--network mynet networks: [mynet] + top-level external: true
--network host network_mode: "host"
--restart unless-stopped restart: unless-stopped
-w, -u, --entrypoint working_dir, user, entrypoint
arguments after the image command: [...]
-it stdin_open: true, tty: true

Gotchas the converter handles

You don't need a top-level version: key any more (see the attribute version is obsolete). If docker compose up then fails with port is already allocated, the old docker run container is probably still running: docker rm -f <name> first.

Last updated 2026-11-20.