Example
docker run -d --name grafana --restart always \
-p 3000:3000 \
-v grafana-data:/var/lib/grafana \
-e GF_SECURITY_ADMIN_PASSWORD=secret \
grafana/grafana:11.3.0
services:
grafana:
image: grafana/grafana:11.3.0
container_name: grafana
restart: always
ports:
- "3000:3000"
volumes:
- grafana-data:/var/lib/grafana
environment:
GF_SECURITY_ADMIN_PASSWORD: secret
volumes:
grafana-data:
Because grafana-data is a named volume rather than a host path, the converter also declares it under
the top-level volumes: key. Compose creates it on the first docker compose up.
Flag mapping
| docker run flag | Compose key |
|---|---|
--name |
container_name |
-p, --publish |
ports |
-v, --volume / --mount |
volumes (plus top-level volumes for named volumes) |
-e, --env / --env-file |
environment / env_file |
--restart |
restart |
--network |
networks or network_mode (host, none, bridge) |
-w, --workdir / -u, --user |
working_dir / user |
--entrypoint, trailing arguments |
entrypoint, command |
-m, --cpus, --shm-size, --ulimit |
mem_limit, cpus, shm_size, ulimits |
--gpus |
deploy.resources.reservations.devices |
--health-cmd, --health-interval … |
healthcheck |
--log-driver, --log-opt |
logging |
-i, -t |
stdin_open, tty |
--cap-add, --device, --privileged |
cap_add, devices, privileged |
Why move from docker run to Compose?
- Reproducible: the whole setup lives in a file you can commit, review and share.
- One command:
docker compose up -dstarts everything,docker compose downstops it. - Networking for free: services in one project share a network and reach each other by name.
- Easy updates: change the image tag and run
docker compose up -d, and only changed services restart.
Useful Compose commands
docker compose up -d # create and start in the background
docker compose ps # status of services
docker compose logs -f api # follow logs of one service
docker compose pull && docker compose up -d # update images
docker compose config # validate and print the final file
Keeping secrets in a .env file? The .env converter can turn it into JSON
or YAML. For other YAML work, see JSON to YAML.
Frequently asked questions
How do I convert a docker run command to docker compose?
Paste the command into the tool above. It parses every flag, including quoted values and backslash line continuations, and writes the matching compose.yaml. Save the output as compose.yaml and start it with docker compose up -d.
Can I convert several containers at once?
Yes. Paste multiple docker run commands, one per line or joined with &&. Each becomes a service in the same compose file. Use depends_on to control start order, and replace --link with service names, because containers in one compose project can reach each other by service name.
Do I still need the "version" key in docker-compose.yml?
No. The top-level version key is obsolete in the Compose Specification, and Docker Compose v2 ignores it with a warning. The generated file leaves it out. compose.yaml is the preferred file name, though docker-compose.yml still works.
Why are the ports quoted?
YAML 1.1 reads values like 22:22 as base-60 numbers (22×60+22 = 1342). Docker’s documentation recommends always quoting port mappings, so the converter does.
What happens to --rm and -d?
Compose services run detached with docker compose up -d, so -d is not needed. --rm has no equivalent for long-running services. For one-off tasks, use docker compose run --rm <service>.