Paste one or more docker run commands and get a clean docker-compose.yml with ports, volumes, environment variables, restart policies, networks, health checks and resource limits. Switch direction to turn a compose file back into docker run commands.
Last updated:
Advertisement
Advertisement
How to use the Docker Run to Compose Converter
Paste your docker run commands in the left box, one or several. Multi-line commands with backslashes are fine.
Read the compose file on the right. It updates as you type, with each container as a service.
Check the notes under the output for flags that were ignored or need attention.
Copy or download docker-compose.yml and start everything with docker compose up -d.
Going the other way? Switch to Compose → docker run, paste a compose file and get the equivalent shell commands.
docker run flags and their compose keys
docker run
docker-compose.yml
Example
--name web
container_name (and the service name)
container_name: web
-p 8080:80
ports
- "8080:80"
-v data:/var/lib/x
volumes + top-level volumes
- data:/var/lib/x
-v ./src:/app:ro
volumes (bind mount)
- ./src:/app:ro
--mount type=bind,…
volumes long syntax
type: bind, source, target
-e KEY=value
environment
KEY: value
--env-file .env
env_file
- .env
--restart unless-stopped
restart
restart: unless-stopped
--network mynet
networks + top-level networks
- mynet
--network host
network_mode
network_mode: host
-w /app, -u 1000
working_dir, user
user: "1000"
--memory 512m --cpus 1.5
mem_limit, cpus
mem_limit: 512m
--health-cmd "…"
healthcheck.test
["CMD-SHELL", "…"]
--gpus all
deploy.resources.reservations.devices
capabilities: ["gpu"]
-it
stdin_open + tty
tty: true
image and trailing arguments
image, command
command: ["npm", "start"]
Everyday docker compose commands
Command
What it does
docker compose up -d
Create and start all services in the background
docker compose ps
List the project's containers and their health
docker compose logs -f api
Follow the logs of one service
docker compose pull && docker compose up -d
Update images and recreate changed containers
docker compose exec db psql -U app
Run a command inside a running service
docker compose config
Validate the file and print it with variables resolved
docker compose down
Stop and remove containers and networks (add -v to delete named volumes too)
Things that do not translate one to one
Names get a project prefix. Compose names networks and volumes <project>_<name>. To attach to data or networks you created with docker run, declare them with external: true.
Relative paths. In compose, ./data is relative to the compose file. With docker run, use an absolute path or $(pwd)/data.
Service discovery. Compose services resolve each other by service name automatically. With docker run you need a user-defined network (the default bridge has no DNS).
Start order.depends_on (optionally with condition: service_healthy) only exists in compose. When running by hand, start databases first.
Variables. Compose substitutes ${VAR} and ${VAR:-default} from the shell and the .env file next to the compose file. A literal $ must be written as $$.
Frequently asked questions
How do I convert a docker run command to docker compose?
Each docker run becomes one service. The image goes to image, --name to container_name, -p to ports, -v to volumes, -e to environment, --restart to restart and --network to networks. Paste the command into this tool to get the YAML automatically, then run docker compose up -d in the folder with the file.
Is the version line still needed in docker-compose.yml?
No. The Compose Specification used by Docker Compose v2 ignores the top-level version key and newer versions warn that it is obsolete, so this tool leaves it out. The file name can be compose.yaml or docker-compose.yml.
What happens to --rm and -d?
Compose has no equivalent of --rm for long-running services, so it is dropped with a note; use docker compose down to remove containers. -d is not part of the file either: you pass it when starting, as in docker compose up -d.
Why are named volumes listed at the bottom of the file?
Compose requires every named volume used by a service to be declared under the top-level volumes key. Bind mounts that start with /, ./ or ~ are host paths and do not need a declaration.
Will my containers keep the same network and volume names?
Compose prefixes the networks and volumes it creates with the project name (usually the folder name), for example myapp_data. To reuse existing ones created with docker run, mark them external: true, or set an explicit name.
Can services reach each other by name?
Yes. Compose puts all services on a default network where each service name is a DNS hostname, so the app can connect to db:5432. With plain docker run you need a user-defined network for that, which is why the reverse conversion creates one.
Is my command sent anywhere?
No. Parsing and conversion run entirely in your browser. Environment variables and secrets in your commands never leave your computer.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.