CLI 目录 横向对比 FCRS-1.0 标准 /llms.txt
← 返回 CLI 目录

Docker Compose

$ docker-compose 官方出品 中风险
Docker · 云原生与基础设施 · Apache-2.0 · macos / linux / windows

Docker Compose(docker-compose / docker compose)通过 compose.yaml 编排多容器应用栈。Compose v2 提供面向 Agent 的全局 --dry-run、规范化 config --format json、结构化 ps --format json、--progress json 与 --ansi never 参数。

FCRS-1.0 综合评分
88 /100
良好 (Good)
高置信度 (实测)
零摩擦安装命令
brew install docker-compose
CLI vs MCP 选型建议 优先选 CLI

直接调用 docker-compose / docker compose 可获得原生 --dry-run、config --format json 与可控日志截取,无需经由 MCP 转译。

Agent 友好度体检单

本地探针实测证据
✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
✓ 支持 Dry-Run
— 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
实测版本
Docker Compose version v5.6.0
冷启动耗时
70 ms
退出码 (help / 非法参数)
0 / 1
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
Usage:  docker compose [OPTIONS] COMMAND

Define and run multi-container applications with Docker

Options:
      --all-resources              Include all resources, even those not
                                   used by services
      --ansi string                Control when to print ANSI control
                                   characters ("never"|"always"|"auto")
                                   (default "auto")
      --compatibility              Run compose in backward compatibility mode
      --dry-run                    Execute command in dry run mode
      --env-file stringArray       Specify an alternate environment file
  -f, --file stringArray           Compose configuration files
      --parallel int               Control max parallelism, -1 for
                                   unlimited (default -1)
      --profile stringArray        Specify a profile to enable
      --progress string            Set type of progress output (auto,
                                   tty, plain, json, quiet)
      --project-directory string   Specify an alternate working directory
                                   (default: the path of the, first
                                   specified, Compose file)
  -p, --project-name string        Project name

Management Commands:
  bridge                  Convert compose files into another model

Commands:
  attach                  Attach local standard input, output, and error streams to a service's running container
  build                   Build or rebuild services
  commit                  Create a new image from a service container's changes
  config                  Parse, resolve and render compose file in canonical format
  cp                      Copy files/folders between a service container and the local filesystem
  create                  Creates containers for a service
  down                    Stop and remove containers, networks
  events                  Receive real time events from containers
  exec                    Execute a command in a running container
  export                  Export a service container's filesystem as a tar archive
  images                  List images used by the created containers
  kill                    Force stop service containers
  logs                    View output from containers
  ls                      List running compose projects
  pause                   Pause services
  port                    List port mappings or print the public port for a spec

FCRS-1.0 六维评分拆解

Agent 友好度 23 / 25

Compose v2 原生在 config 与 ps 上支持 --format json,并提供 --progress json、--ansi never 与全局 --dry-run。

  • docker-compose config --format json and ps --format json emit valid JSON
  • --ansi never and --progress json eliminate TTY escape noise
安全与权限边界 21 / 25

生命周期命令支持 --dry-run 预演且 config 可静态校验,但误传 down -v 会永久删除数据卷。

  • Global --dry-run flag previews mutations without executing them
  • down -v destroys named data volumes if passed carelessly
安装与运行摩擦 14 / 15

覆盖 macOS、Linux 与 Windows 的 Go 二进制/插件,运行时需依赖 Docker/Colima 等容器守护进程。

  • Distributed via Homebrew, Docker Desktop, and GitHub Releases
能力覆盖与边际价值 13 / 15

本地多服务栈事实标准,集成了构建、启停、分服务日志截取与 Profile 切换。

  • Handles build, up, ps, logs, and exec for multi-service stacks
维护与来源背书 9 / 10

Docker 官方维护的 Compose v2 项目(docker/compose),Apache-2.0 协议。

  • Official docker/compose repository
文档与可验证性 8 / 10

官方 Compose CLI 参考文档齐全,--help 规范。

  • Official docs at docs.docker.com/reference/cli/docker/compose/

安全边界、鉴权与放权指南

鉴权方式
无需鉴权 本地配置文件
凭证存储位置

使用本地 Docker 套接字(DOCKER_HOST)以及保存在 ~/.docker/config.json 中的镜像仓库凭证。

潜在副作用
只读查询 本地写入 破坏性删除
费用与配额提示

CLI 本体为 Apache-2.0 开源免费;企业级规模使用 Docker Desktop 桌面端时另适用 Docker Desktop 授权条款。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Docker Compose Agent Rules
- Run `docker-compose config --format json` and `docker-compose --dry-run up -d` before starting services.
- Always pass `--ansi never` (and `--tail=100` on `logs`) in non-TTY agent runs.
- Never run `docker-compose down -v` without explicit confirmation, as `-v` deletes named volumes.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 校验并展开 compose.yaml 配置
docker-compose config --format json

以只读方式展开环境变量、Profile 与覆盖文件并输出规范 JSON,提前捕获结构错误。

以 JSON 列出编排栈容器状态
docker-compose ps --format json

以结构化 JSON 输出各服务容器的运行与退出状态。

受控写入与预演

使用 --dry-run 预演应用栈启动
docker-compose --dry-run up -d

在不实际改动守护进程状态的情况下模拟镜像拉取、网络创建与容器启动步骤。

核心优势

  • + 全局 --dry-run 可安全预演 up、down 与 pull 变更流程。
  • + config 与 ps 原生支持 --format json,配合 --ansi never 便于精准解析。
  • + config 解析可在启动前捕获变量替换与 YAML 语法问题。

注意事项与踩坑点

  • ! 容器生命周期操作依赖可用的 Docker 兼容守护进程(DOCKER_HOST)。
  • ! docker-compose down -v 会不可逆地销毁命名数据卷。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI