Docker Run 转 Compose 工具

将 docker run 命令转换为 docker-compose.yml 格式,支持端口、数据卷、环境变量、网络等 30+ 参数。

示例:

支持使用反斜杠(\)续行的多行命令。

-d、--rm、-it、--init 等运行时参数不会写入 compose 文件。

What Is the Docker Run to Compose Converter?

This tool converts a docker run command into a valid docker-compose.yml service definition. Paste any docker run command — with ports, volumes, environment variables, networks, restart policies, and more — and get a ready-to-use Compose file in seconds.

It is especially useful when you have an existing container running from a docker run command and want to migrate it to a Compose-managed stack, or when you find a quick-start command in documentation and need to turn it into a reproducible Compose file.

How to Use the Docker Run to Compose Converter

  1. Paste your docker run command into the input box. You can include docker run or just the flags and image name.
  2. Multi-line commands with backslash continuation are supported — paste them as-is.
  3. Click Convert. The docker-compose.yml output appears below.
  4. Copy the output and save it as docker-compose.yml in your project.
  5. Use the example buttons to try Nginx, PostgreSQL, or Redis presets.

Features

  • Supports 30+ docker run flags including ports, volumes, env vars, networks, restart, user, workdir, entrypoint, labels, capabilities, and healthcheck
  • Multi-line backslash-continuation commands parsed correctly
  • Generates clean docker-compose v2 format (no deprecated version key)
  • Auto-detects service name from container name or image name
  • 3 built-in examples: Nginx, PostgreSQL, Redis
  • One-click copy to clipboard

FAQ

What docker run flags are supported?

The converter supports the most common flags: -p/--publish (ports), -v/--volume (volumes), -e/--env (environment variables), --env-file, --name, --restart, --network, --hostname, -u/--user, -w/--workdir, --entrypoint, --label, --cap-add, --cap-drop, --privileged, --add-host, --dns, --device, --sysctl, --security-opt, --memory, --cpu-shares, --pid, --ipc, and healthcheck flags.

Can I use multi-line docker run commands with backslash continuation?

Yes. You can paste multi-line commands that use backslash-newline continuation (the standard shell convention for splitting long commands across lines). The parser normalizes them automatically.

What version of docker-compose format does this generate?

The output uses the modern top-level services: format without a version: key, which is compatible with Docker Compose v2 and later. This is the recommended format as of Docker Desktop 3.4+.

Does -d / --rm affect the output?

No. Flags like -d (detached), --rm (remove on exit), -it, and --init control container lifecycle at runtime but have no equivalent in docker-compose.yml. They are silently ignored.