docker run to docker-compose
Turn a docker run command into docker-compose.yml: ports, volumes, environment, networks, restart policy, cap-add, healthcheck and command are parsed; unsupported options are kept as comments.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Supports -p/--publish, -v/--volume, -e/--env, --name, --network, --restart, --cap-add, --health-*, --entrypoint and the command after the image; -d and --rm are explained in comments.
docker-compose.yml
What this tool does
- Turn a docker run command copied from docs or a colleague into docker-compose.yml without looking up every compose field name.
- Turn a one-off container into a maintainable service definition: ports, volumes, environment, restart policy, cap-add and healthchecks all map to their fields.
- Find out how to express a flag in compose: anything that cannot be mapped is listed as a comment with its equivalent, such as --rm needing docker compose run --rm.
- Cross-check what the generated file contains: the stats row reports the number of ports, volumes, environment entries and cap-add values.
Example
Input
docker run -d --name web -p 8080:80 -v /srv/html:/usr/share/nginx/html:ro -e NODE_ENV=production --network appnet --restart unless-stopped nginx:alpine nginx -g 'daemon off;'
Output
# 无法自动转换的选项(notes / unsupported):
# - -d / --detach → compose 默认后台运行,用 `docker compose up -d`
version: '3.8'
services:
web:
image: nginx:alpine
container_name: web
restart: unless-stopped
ports:
- 8080:80
environment:
- NODE_ENV=production
volumes:
- /srv/html:/usr/share/nginx/html:ro
networks:
- appnet
command:
- nginx
- -g
- daemon off;
networks:
appnet: {}Everything after the image name becomes the command array verbatim, and a custom network used by --network is declared at the top level automatically. The leading comment block is emitted by the tool and is always in Chinese.
Frequently asked questions
Which options are converted automatically?
-p/--publish, -v/--volume, -e/--env, --name, --network, --restart, --cap-add, --health-*, --entrypoint, --hostname, plus the command after the image name. Everything else is kept as a comment at the top of the file rather than dropped silently.
Why are -d and --rm not written into the YAML?
Because compose has no field for them: a service runs in the background by default (docker compose up -d), and disposable containers use docker compose run --rm <service>. Both are explained as comments so you do not assume they already apply.
Are volume paths rewritten?
No. The mount string is preserved as-is, including :ro / :rw suffixes. Only a source that is not an absolute path is treated as a named volume and declared under the top-level volumes key, so -v data:/var/lib/data yields volumes: { data: {} }. Windows drive paths are recognised too.
What happens with --network host?
The three built-in networks host, none and bridge become network_mode and no top-level network is created. Any other name (appnet, for example) is treated as a custom network, added to the service networks list and declared at the top level.
Is the command uploaded anywhere?
No. Parsing and YAML generation happen in the browser, the page makes no network requests, and commands containing internal addresses or passwords can be pasted safely.
Keywords:docker rundocker composedocker-compose.ymlcompose容器转换containeryamldevops