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

Docker CLI

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

Docker CLI(docker)用于构建、检查与运行容器、镜像、卷与 Compose 应用栈,在 ps、images、inspect 与 compose ls 中普遍支持 --format json 与 Go 模板字段投影,并支持 --context 端点隔离。

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

大模型对 docker 语法极为熟稔,直接调用本地 --format json 与 Go 模板投影比搭建 MCP 更加迅捷。

Agent 友好度体检单

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

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Authenticate to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  builder     Manage builds
  checkpoint  Manage checkpoints
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  plugin      Manage plugins
  system      Manage Docker
  volume      Manage volumes

Swarm Commands:
  config      Manage Swarm configs
  node        Manage Swarm nodes
  secret      Manage Swarm secrets
  service     Manage Swarm services
  stack       Manage Swarm stacks
  swarm       Manage Swarm

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage s

FCRS-1.0 六维评分拆解

Agent 友好度 23 / 25

几乎所有列表与检查命令均支持 --format json 与 {{json .Field}} Go 模板表达式。

  • Universal --format json and Go template projection
安全与权限边界 19 / 25

--context 可明确隔离本地与远程守护进程,但 Docker Socket 权限近似宿主机 root 且 system prune 清理命令破坏性较高。

  • Supports --context isolation; socket access carries host privileges
安装与运行摩擦 14 / 15

单文件 Go CLI 跨平台极易安装,但容器运行操作依赖本地或远端 Docker Engine 守护进程。

  • Available on macOS, Linux, and Windows
能力覆盖与边际价值 14 / 15

单工具覆盖镜像构建、容器运维、网络管理及 docker compose 编排。

  • Full container and Compose lifecycle in one CLI
维护与来源背书 9 / 10

Docker 官方仓库(docker/cli)在 Apache-2.0 下持续维护。

  • Official docker/cli under Apache-2.0
文档与可验证性 9 / 10

拥有极其完善的官方 CLI 手册与内置 --help。

  • Complete reference at docs.docker.com

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

鉴权方式
本地配置文件 系统钥匙串 环境变量密钥
凭证存储位置

将镜像仓库认证与凭据助手配置保存在 ~/.docker/config.json(结合系统钥匙串),并读取 DOCKER_HOST / DOCKER_CONTEXT。

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

Docker CLI 本身开源免费(Apache-2.0);大型企业使用 Docker Desktop 需遵守商业许可条款。

可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# Docker CLI Agent Rules
- Always pass `--format json` (or `--format '{{json .}}'`) on `ps`, `images`, `network ls`, and `inspect`.
- Verify `docker context show` before targeting remote daemons.
- Never run `docker system prune -af` or `docker volume rm` without explicit user approval.

Agent 高频安全命令配方

只读查询(安全推荐)

以 JSON 格式列出运行中容器
docker ps --format json --no-trunc

为每个活跃容器输出逐行分隔的 JSON(NDJSON)状态对象。

按需提取容器状态配置
docker inspect my-container --format '{{json .State}}'

使用 Go 模板仅提取 .State 字段,避免返回整份冗长元数据。

受控写入与预演

在不启动服务的前提下校验 Compose 配置
docker compose config --quiet

本地解析并校验 compose.yaml 的语法与环境变量插值。

核心优势

  • + --format json 与 Go 模板(--format '{{json .State}}')可原生裁剪返回字段。
  • + 大模型对 docker 与 docker compose 语法预训练充分,准确率极高。
  • + Go 客户端响应迅速,支持 --context 切换目标环境。

注意事项与踩坑点

  • ! docker ps --format json 输出的是按行分隔的 NDJSON 而非单个 JSON 数组。
  • ! 拥有 Docker 守护进程 Socket 访问权限在宿主机上等效于高特权操作。

已验证兼容的 Agent 宿主

Claude Code Codex CLI Gemini CLI