Docker for AI agents
The Docker CLI for coding agents: list containers, read logs, build images, and run Compose stacks, with the prune and volume commands agents must avoid.
What Docker does for an agent
The Docker CLI is the command-line client for Docker Engine. It builds images, runs and inspects containers, and with docker compose starts multi-container stacks from a compose file.
Agents mostly use it to bring up a local database or service, read container logs while debugging, and check that a Dockerfile still builds.
Official site: www.docker.com
Install Docker
The install commands from the official docs. Check it worked with docker version.
curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh
Signing in Docker for an agent
No sign-in is needed for local containers. Pushing or pulling private images needs docker login to the registry; in CI, use a registry access token rather than a password.
docker login
What agents use Docker for
Example commands with placeholder names. Swap in your own project, app, or file names.
List running containers
docker ps
Read the last log lines of a container
docker logs --tail 100 my-container
Build an image
docker build -t my-app:dev .
Start a Compose stack in the background
docker compose up -d
Read logs from one Compose service
docker compose logs --tail 100 api
Safety rules for agents
Safe to run without asking
docker psdocker logs --tail Ndocker imagesdocker inspectdocker compose ps / logs
Ask a human first
docker pushdocker compose down -vdocker volume rm / prunedocker system prunedocker run --privileged or with host mounts
- Never run docker system prune or remove volumes on the agent's own initiative; volumes hold local database data.
- Use --tail instead of -f when reading logs so the command returns.
- Do not mount the host root, the Docker socket, or home directories into containers without approval.
AGENTS.md or CLAUDE.md snippet
Paste this into the instruction file your agent reads at the start of every session, then adjust the rules to your setup.
## Docker (docker) Use `docker` for building images and running, inspecting, and debugging local containers and Compose stacks. - Check it is installed with `docker version`. If it is missing, ask before installing it. - Auth: credentials are set up by a human. Never print or commit them. - Run without asking (read-only): `docker ps`, `docker logs --tail N`, `docker images`, `docker inspect`, `docker compose ps / logs`. - Ask a human first (changes or deletes things): `docker push`, `docker compose down -v`, `docker volume rm / prune`, `docker system prune`, `docker run --privileged or with host mounts`. - Never run docker system prune or remove volumes on the agent's own initiative; volumes hold local database data. - Use --tail instead of -f when reading logs so the command returns. - Do not mount the host root, the Docker socket, or home directories into containers without approval. - Prefer JSON output where the command supports it, and keep output short.
Docker or an MCP server?
No official MCP server. Docker's MCP work, such as the MCP Catalog, Toolkit, and Gateway, focuses on running MCP servers in containers rather than replacing the docker CLI. Search the directory for servers that manage containers.
Rule of thumb: in a terminal agent that a human has signed in, the CLI is usually faster and cheaper in context. In a chat client without a shell, or when you want a fixed set of typed tools, use an MCP server.
Other Dev & Git tools
Docker questions
How do I install Docker?
Linux dev machines (Docker's convenience script): curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh. Check the install with docker version, and see the Docker docs for other platforms.
How does an AI agent authenticate Docker?
No sign-in is needed for local containers. Pushing or pulling private images needs docker login to the registry; in CI, use a registry access token rather than a password.
Which Docker commands are safe for an agent to run?
Commands that only read state are safe to run without asking: docker ps; docker logs --tail N; docker images; docker inspect; docker compose ps / logs. Ask a human before anything that changes or deletes something: docker push; docker compose down -v; docker volume rm / prune; docker system prune; docker run --privileged or with host mounts.
Is there an MCP server for Docker?
Docker's MCP work, such as the MCP Catalog, Toolkit, and Gateway, focuses on running MCP servers in containers rather than replacing the docker CLI. Search the directory for servers that manage containers.