Docker Run to Docker Compose Converter (and Back)
Turn a docker run command into a docker-compose.yml service, or a Compose service back into docker run.
services:
db:
image: postgres:16
container_name: db
restart: unless-stopped
environment:
POSTGRES_PASSWORD: change-me
POSTGRES_DB: app
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "127.0.0.1:5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
retries: 5
volumes:
pgdata:
name: pgdata
- -d / --detach dropped: use "docker compose up -d" to run in the background.
- Named volumes keep their exact name ("name:") so Compose reuses the volume docker run created instead of making a new, empty "<project>_<volume>" one.
Runs entirely in your browser. Commands and Compose files, including any passwords in them, are never sent anywhere. Browse all free tools.
Found a problem, or something that could be better? We read every message and we fix things quickly.
This docker run to Docker Compose converter turns a docker run command, the kind you copy from a project’s README, into a docker-compose.yml service: ports, volumes, environment variables, networks, restart policy, healthcheck, capabilities, devices, GPU access and dozens of other options. It also works in reverse, turning each service in a Compose file into the equivalent docker run command for a quick test or a system without Compose.
The conversion is careful about the details that break real deployments. Ports are quoted, because YAML 1.1 reads an unquoted 22:22 as a base-60 number. Named volumes keep their exact name, so Compose reuses the data docker run created instead of starting an empty “<project>_<volume>”. $(pwd) becomes a relative path. Flags that only affect the CLI session, such as -d and --rm, are dropped with a note, and anything without a Compose equivalent is listed as a warning rather than silently lost.
How to use
- Paste a docker run command into the left box, or click an example. Multi-line commands with backslashes are fine.
- Read the generated docker-compose.yml on the right, and check the notes and warnings below it.
- Copy the YAML or download it as docker-compose.yml, put it in your project directory and run docker compose up -d.
- To go the other way, switch to “Compose → docker run”, paste a Compose file, and copy the command for each service.
Frequently asked questions
What is the difference between docker run and docker compose?
docker run starts one container from options on the command line. Docker Compose describes one or more containers, their networks and volumes in a YAML file and starts them together with docker compose up. Compose is easier to keep in version control, to review and to re-run identically, and services in the same Compose project can reach each other by service name.
Do I still need the version: line in docker-compose.yml?
No. The top-level version key is obsolete under the Compose Specification used by Docker Compose v2, and current versions print a warning that it is ignored. This converter leaves it out. Files are usually named compose.yaml now, though docker-compose.yml is still read.
Why are my volume’s data missing after switching to Compose?
Compose prefixes named volumes with the project name, so a volume called pgdata becomes myproject_pgdata, which is a new, empty volume. To reuse the volume docker run created, declare it at the top level with name: pgdata (this converter does that), or mark it external: true. Bind mounts (paths starting with / or ./) are not affected.
What happens to -d, -it and --rm?
-d is a property of how you start the containers, so use docker compose up -d. -i and -t become stdin_open: true and tty: true. --rm has no per-service equivalent: docker compose down removes the containers, and docker compose run --rm exists for one-off commands.
How are GPU options converted?
--gpus all becomes a device reservation under deploy.resources.reservations.devices with driver: nvidia, count: all and capabilities: [gpu], which is the form documented for Docker Compose. Specific GPUs (--gpus '"device=0,1"') become device_ids. You still need the NVIDIA Container Toolkit installed on the host.
Is my command sent to a server?
No. Parsing and conversion happen in your browser, so environment variables, passwords and internal hostnames in the command never leave your machine. Still, treat a Compose file that contains secrets like a password file: move them to an env_file that is listed in .gitignore.
docker run flags and their Compose keys
• -p 8080:80 → ports: ["8080:80"] · --expose → expose
• -v /host:/ctr or -v name:/ctr → volumes · --mount → long-syntax volumes · --tmpfs → tmpfs
• -e KEY=value → environment · --env-file → env_file · -l / --label → labels
• --name → container_name · -h → hostname · -u → user · -w → working_dir
• --restart → restart · --network → networks or network_mode (host, none, container:…) · --network-alias, --ip → per-network aliases and ipv4_address
• --entrypoint → entrypoint · arguments after the image → command
• --health-cmd/-interval/-timeout/-retries/-start-period → healthcheck · --no-healthcheck → healthcheck.disable
• --cap-add/--cap-drop → cap_add/cap_drop · --device → devices · --privileged, --read-only, --init → the same names
• -m / --memory → mem_limit · --cpus → cpus · --shm-size → shm_size · --ulimit → ulimits · --sysctl → sysctls
• --log-driver/--log-opt → logging · --add-host → extra_hosts · --dns → dns · --gpus → deploy.resources.reservations.devices
After converting: make it a real Compose project
A one-to-one conversion is a starting point. Once several containers live in one file, replace --link and hard-coded container IPs with service names (the app reaches the database at db:5432), add depends_on with condition: service_healthy so the app waits for the database’s healthcheck, and drop container_name unless something outside Compose needs a fixed name, since it prevents scaling a service. Move passwords from environment into an .env file or Compose secrets, and keep that file out of Git.
Related free tools
- Subnet Calculator — Network, broadcast, host range and mask for any CIDR; split networks with VLSM, expand IPv6 and find overlapping ranges.
- Chmod Calculator — Tick read, write and execute boxes to get the octal mode and chmod command, or decode 755, 644 and rwxr-xr-x.
- .gitignore Generator — Combine .gitignore templates for languages, frameworks, editors and operating systems into one clean file.
- JSON Formatter — Pretty-print, minify and validate JSON, with parse errors located by line and column. In your browser, no upload.
- Cron Expression Generator — Build a cron schedule from dropdowns or paste one, read it in plain English, and see the next 10 run times in your zone and UTC. Free, in your browser.