Building AI Agents with Docker Agent
https://www.kdnuggets.com/building-ai-agents-with-docker-agent📌 Docker Agent:用YAML把AI Agent打包成「容器」
TL;DR:Docker推出開源CLI工具Docker Agent,讓AI agent像容器一樣用YAML定義、版本控管、透過OCI registry分發。
Docker靠「打包一次、到處執行」這個理念建立起地位,現在它把同樣的邏輯搬到AI agent身上:不用寫程式碼,用一份declarative設定檔描述agent,透過CLI外掛執行,再用你本來就在用的OCI registry來分發。
🤔 AI agent能不能像容器映像檔一樣被定義、版本化、分享?
這是Docker Agent要填補的空缺。它是一個Apache 2.0授權的開源CLI外掛,由Docker Engineering團隊開發,安裝後以docker agent指令執行,標語直接寫明目標:「run AI agents like containers」。根據文章,這個專案在pkg.go.dev上的Go module紀錄顯示,最早的標籤版本可追溯到2026年3月,成長速度很快,目前已累積超過3,300個GitHub星數與近10,000次commit。文章也提到,這並非憑空出現,而是Docker在2025年陸續鋪墊的成果:先是讓Docker Compose支援agent與AI模型,接著推出Docker Model Runner讓使用者能在本機跑模型而不需雲端API key,Docker Agent則是這些基礎落地成的獨立工具。
🧩 YAML定義agent,provider不綁定,支援多agent協作
Docker Agent的設計理念有幾個重點:agent用YAML(或HCL)定義而非寫程式碼,門檻因此降低;它是provider-agnostic的,支援OpenAI、Anthropic、Gemini、AWS Bedrock、Mistral、xAI以及透過Docker Model Runner執行的本機模型,設定檔不會被綁死在單一供應商上;它支援真正的多agent協作(multi-agent orchestration),可以組出一群各自專精的agent互相委派工作;工具生態系包含內建工具,以及任何MCP伺服器,可以在本機、遠端,或是獨立的Docker容器中執行以取得隔離性;最後,呼應容器的類比,做好的agent可以推送到、或從任何OCI相容的registry拉取,用的正是Docker映像檔原本就在用的那套分發機制。
💡 三步驟上手:安裝、設定模型、寫第一個agent
文章給出完整的手把手教學。安裝有三條路:Docker Desktop 4.63以上版本已內建外掛,直接執行docker agent即可;透過Homebrew執行brew install docker-agent安裝二進位檔,可用docker-agent指令執行,或將其symlink到~/.docker/cli-plugins/docker-agent以改用docker agent這種呼叫形式;也可以直接從GitHub Releases下載二進位檔,再用同樣方式建立symlink。模型設定則有兩個選項:設定雲端供應商的API key作為環境變數(如ANTHROPIC_API_KEY),或完全不用雲端key,透過Docker Model Runner在本機跑模型。安裝完成後可用docker agent --help確認。
最小可行的agent只需要一份YAML檔,裡面定義root這個進入點agent(每份設定檔都必須有名為root的agent),指定model(格式為provider/模型名稱,如anthropic/claude-sonnet-4-5)、description(簡短描述,當設定檔中有多個agent時尤其重要)、instruction(也就是system prompt,用白話描述agent的行為)、以及toolsets(agent可用的能力清單,例如filesystem賦予讀寫檔案權限、shell允許執行指令、think讓agent在行動前有結構化的推理空間,對原生推理能力較弱的模型特別有用)。寫好之後可用docker agent run agent.yaml進入互動式對話,或用docker agent run --exec agent.yaml "任務描述"以非互動方式單次執行,適合用在腳本或CI中。
若要讓agent接上外部能力,文章特別點出MCP的使用建議:將MCP伺服器跑在獨立的Docker容器中,而不是當成本機裸執行的process。設定檔裡只要在mcp工具型別的ref欄位加上docker:前綴(如docker:duckduckgo),就會讓該MCP伺服器在自己的容器中執行;文章強調這是官方建議的用法,因為預設就具備安全性與隔離性,而不是把系統存取權信任給一個任意的本機process。此外還有memory工具型別,可以在指定路徑建立持久化儲存,讓agent能跨對話回憶重要發現。
文章最後示範了一個多agent團隊的完整案例:一個內容研究團隊,由root協調者將主題委派給researcher進行網路搜尋,再將研究結果交給writer產出報告。協調者在設定中透過sub_agents: [researcher, writer]宣告可委派的下游agent,researcher則搭配docker:duckduckgo這個MCP工具與memory持久化儲存來完成任務。
⚠️ 文章聚焦在安裝與實作步驟,並未提及Docker Agent在效能、穩定性或與其他agent框架(如LangGraph、AutoGen)相比的優劣,這部分留白。
🎯 實務啟示
如果你的團隊已經熟悉Docker生態系的映像檔、registry與CI流程,Docker Agent的價值在於把這整套熟悉的分發與版本控管機制直接套用到AI agent上,尤其是用容器隔離MCP伺服器這個細節,值得在設計agent工具呼叫的安全邊界時參考。
🔗 來源
- 標題:Building AI Agents with Docker Agent
- 作者/機構:Shittu Olumide, KDnuggets
- 連結:https://www.kdnuggets.com/building-ai-agents-with-docker-agent
#DockerAgent #AIAgents #MCP #MultiAgent #OpenSource #DevTools #LLM #Containerization #CLI #AgentOrchestration
原始資料 KDnuggets · 收集於 2026-10-08
摘要原文
Building AI Agents with Docker Agent Docker Agent is an open-source, Apache 2.0-licensed CLI plugin built by Docker Engineering, installed and run as docker agent. Its own tagline states the goal plainly: run AI agents like containers. By Shittu Olumide , Technical Content Specialist on October 8, 2026 in Artificial Intelligence Docker built its reputation on one idea: package software once, run it anywhere, the same way, every time. Docker Agent applies that same idea to AI agents : describe them in a declarative config instead of code, run them through a CLI plugin, and distribute them through the same OCI registries that already store your container images. If you've ever wished an AI agent could be defined, versioned, and shared like a container, that's the gap this tool fills. This is a full, hands-on tutorial, from a completely bare install to a real, working multi-agent team. What Is Docker Agent? Docker Agent is an open-source, Apache 2.0-licensed CLI plugin built by Docker Engineering, installed and run as docker agent . Its own tagline states the goal plainly: run AI agents like containers . Its Go module history on pkg.go.dev shows early tagged releases from March 2026, and it's grown quickly since; the project has already passed 3,300 GitHub stars and nearly 10,000 commits. It didn't appear out of nowhere. Docker spent 2025 building toward exactly this: a July 2025 announcement extended Docker Compose to support agents and AI models directly , and Docker Model Runner shipped as a way to run models locally without a cloud API key. Docker Agent is the product of that groundwork landing in one dedicated tool, rather than a single feature bolted onto Compose. What actually makes it distinctive: agents are defined in YAML (or HCL, if you prefer that syntax), not code, which means no software engineering background is required to build one. It's provider-agnostic, working with OpenAI, Anthropic, Gemini, AWS Bedrock, Mistral, xAI, and fully local models through Docker Model Runner, so a config isn't locked to one vendor. It supports genuine multi-agent orchestration , teams of specialized agents that delegate work to each other. Its tool ecosystem includes built-in tools plus any MCP server , run locally, remotely, or inside its own Docker container for isolation. And, tying back to the container analogy directly, finished agents can be pushed to and pulled from any OCI-compatible registry — the same distribution mechanism Docker images already use. Prerequisites and Installing Docker Agent You need three things: Docker installed on your machine, a way to actually run it, and access to at least one language model. Installation has three real paths. If you're running Docker Desktop 4.63 or newer, the plugin is already there; just run docker agent . Via Homebrew, brew install docker-agent installs the binary directly; run it as docker-agent , or symlink it to ~/.docker/cli-plugins/docker-agent to use the docker agent form instead. For a binary release, download it directly from GitHub Releases and symlink it the same way. Setting up a model comes next, and you have two real options. The simplest is a cloud provider's API key, set as an environment variable: export ANTHROPIC_API_KEY=sk-ant-your-key-here # or OPENAI_API_KEY, GOOGLE_API_KEY, depending on your provider Or skip a cloud key entirely and run a model locally through Docker Model Runner, which the rest of this tutorial will note as an alternative wherever a model is specified. Confirm the install worked with: docker agent --help If that prints a list of commands rather than an error, you're ready for the first real agent. Building Your First Agent The smallest real Docker Agent is a single YAML file. Create agent.yaml : agents: root: model: anthropic/claude-sonnet-4-5 description: A helpful coding assistant instruction: | You are an expert software developer. Help users write clean, efficient code. Explain your reasoning step by step. toolsets: - type: filesystem - type: shell - type: think Code explanation : root is the name of this agent, and every config needs at least one agent with this exact name as its entry point model follows a provider/model-name format, here pointing to Claude Sonnet 4.5 through Anthropic description is a short summary the runtime uses to identify the agent, which becomes important the moment more than one agent exists in a config instruction is the system prompt — the actual behavior you're defining — written in plain language toolsets is a list of capabilities this agent can use: filesystem grants read and write access to files; shell allows running commands think gives the agent a structured space to reason step by step before acting, useful for models without strong native reasoning built in Run it with the interactive terminal UI: docker agent run agent.yaml Or run it non-interactively for a single task, useful in scripts or CI: docker agent run --exec agent.yaml "Create a Dockerfile for a Node.js app" Code explanation: The first command drops you into a live chat session with the agent The --exec flag skips the interactive loop entirely, sends one instruction, prints the result, and exits — the form you'd actually use if you were calling this agent from a script rather than a terminal Giving Your Agent Real Tools A filesystem and a shell are useful, but a genuinely capable agent usually needs to reach outside your machine too. Docker Agent's MCP support is how that happens, and it's worth understanding the recommended pattern specifically: running an MCP server inside its own Docker container, isolated from your host system, rather than as a bare local process. agents: root: model: anthropic/claude-sonnet-4-5 description: Research assistant with memory and web search instruction: | You are a research assistant. Search the web for information, remember important findings, and provide thorough analysis. toolsets: - type: think - type: memory path: ./research.db - type: mcp ref: docker:duckduckgo Code explanation : The memory toolset gives the agent a persistent store at ./research.db , so it can recall facts across turns in a session rather than starting fresh every message The mcp toolset with ref: docker:duckduckgo is the detail worth pausing on — that docker: prefix tells Docker Agent to run the DuckDuckGo MCP server inside its own container , which is the officially recommended way to use MCP tools specifically because it's secure and isolated by default rather than trusting an arbitrary local process with access to your system. This config also validated cleanly against the real schema, confirming the field names and structure are exactly right Building a Multi-Agent Team This is the part that actually shows what Docker Agent is built for. Rather than one agent trying to do everything, you define a small team — each member with a narrow role — and a coordinator that delegates between them. The project for this section: a content research team, a coordinator that hands a topic to a researcher, then passes the findings to a writer for a final report. agents: root: model: anthropic/claude-sonnet-4-5 description: Coordinator for a content research team instruction: | You are a content lead coordinating a small research team. When given a topic, delegate web research to the researcher, then pass the findings to the writer to produce a short, well-organized report. Review the final output before presenting it to the user. sub_agents: [researcher, writer] toolsets: - type: think researcher: model: openai/gpt-5 description: Web researcher who gathers and summarizes findings instruction: | Search the web for current, credible information on the given topic. Summarize the key findings in a structured list, noting the source for each claim. toolsets: - type: mcp ref: docker:duckduckgo - type: memory path: ./research.
由 claude-code/sonnet 自動生成