Docker Compose
$ docker-compose 官方出品 中风险Docker Compose(docker-compose / docker compose)通过 compose.yaml 编排多容器应用栈。Compose v2 提供面向 Agent 的全局 --dry-run、规范化 config --format json、结构化 ps --format json、--progress json 与 --ansi never 参数。
brew install docker-compose 直接调用 docker-compose / docker compose 可获得原生 --dry-run、config --format json 与可控日志截取,无需经由 MCP 转译。
Agent 友好度体检单
本地探针实测证据抓取的 --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 六维评分拆解
Compose v2 原生在 config 与 ps 上支持 --format json,并提供 --progress json、--ansi never 与全局 --dry-run。
docker-compose config --format jsonandps --format jsonemit valid JSON--ansi neverand--progress jsoneliminate TTY escape noise
生命周期命令支持 --dry-run 预演且 config 可静态校验,但误传 down -v 会永久删除数据卷。
- Global
--dry-runflag previews mutations without executing them down -vdestroys named data volumes if passed carelessly
覆盖 macOS、Linux 与 Windows 的 Go 二进制/插件,运行时需依赖 Docker/Colima 等容器守护进程。
- Distributed via Homebrew, Docker Desktop, and GitHub Releases
本地多服务栈事实标准,集成了构建、启停、分服务日志截取与 Profile 切换。
- Handles build, up, ps, logs, and exec for multi-service stacks
Docker 官方维护的 Compose v2 项目(docker/compose),Apache-2.0 协议。
- Official
docker/composerepository
官方 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 授权条款。
# 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 高频安全命令配方
只读查询(安全推荐)
docker-compose config --format json
以只读方式展开环境变量、Profile 与覆盖文件并输出规范 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会不可逆地销毁命名数据卷。