Skip to content
CLI tool · Dev & Git

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.

dockerby Docker
What it is

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

Install Docker

The install commands from the official docs. Check it worked with docker version.

Linux dev machines (Docker's convenience script)
curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh
Auth

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.

Sign in to a registry (human)
docker login
Common agent tasks

What agents use Docker for

Example commands with placeholder names. Swap in your own project, app, or file names.

  1. List running containers

    docker
    docker ps
  2. Read the last log lines of a container

    docker
    docker logs --tail 100 my-container
  3. Build an image

    docker
    docker build -t my-app:dev .
  4. Start a Compose stack in the background

    docker
    docker compose up -d
  5. Read logs from one Compose service

    docker
    docker compose logs --tail 100 api
Safety

Safety rules for agents

Safe to run without asking

  • docker ps
  • docker logs --tail N
  • docker images
  • docker inspect
  • docker compose ps / logs

Ask a human first

  • 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.
Agent instructions

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.

AGENTS.md
## 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.
CLI or MCP server?

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.

Same category
All Dev & Git tools
FAQ

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.