| name | docker |
| category | system |
| description | Manage Docker containers, images, volumes, networks, and Compose stacks. Use when the user asks to build, run, stop, restart, remove, inspect, or debug containers; pull, push, tag, or delete images; manage volumes and networks; run docker compose services; view logs or resource usage; clean up unused objects; or troubleshoot container issues. Keywords: docker, container, image, dockerfile, compose, volume, network, registry, build, deploy.
|
| license | MIT |
| compatibility | Requires docker CLI (v20+). Docker Compose V2 integrated as `docker compose`. |
| metadata | {"author":"zeph","version":"1.0"} |
Docker Operations
Container Lifecycle
List containers
docker ps
docker ps -a
docker ps -q
docker ps -f "status=exited"
docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}"
Create and run
docker run IMAGE
docker run -d --name NAME IMAGE
docker run -d -p 8080:80 IMAGE
docker run -d -e KEY=VALUE -e KEY2=VALUE2 IMAGE
docker run -d --env-file .env IMAGE
docker run -it IMAGE /bin/bash
docker run --rm IMAGE
docker run -d -v /host/path:/container/path IMAGE
docker run -d -v myvolume:/data IMAGE
docker run --read-only IMAGE
docker run -d --memory=512m --cpus=1.5 IMAGE
docker run -d --restart=unless-stopped IMAGE
docker run -d --network=mynet IMAGE
docker run -d \
--health-cmd="curl -f http://localhost/ || exit 1" \
--health-interval=30s \
--health-timeout=10s \
--health-retries=3 \
IMAGE
Stop, start, restart, remove
docker stop CONTAINER
docker stop -t 30 CONTAINER
docker start CONTAINER
docker restart CONTAINER
docker kill CONTAINER
docker rm CONTAINER
docker rm -f CONTAINER
docker container prune -f
Execute commands in running containers
docker exec CONTAINER COMMAND
docker exec -it CONTAINER /bin/bash
docker exec -u root CONTAINER COMMAND
docker exec -e VAR=value CONTAINER COMMAND
docker exec -w /app CONTAINER COMMAND
Logs and Inspection
Logs
docker logs CONTAINER
docker logs -f CONTAINER
docker logs --tail 100 CONTAINER
docker logs --since 2h CONTAINER
docker logs -t CONTAINER
docker logs --tail 50 -f CONTAINER
Inspect and monitor
docker inspect CONTAINER
docker inspect --format '{{.State.Status}}' CONTAINER
docker inspect --format '{{.NetworkSettings.IPAddress}}' CONTAINER
docker stats
docker stats --no-stream CONTAINER1 CONTAINER2
docker top CONTAINER
docker port CONTAINER
docker diff CONTAINER
Image Management
Build
docker build -t NAME:TAG .
docker build -f Dockerfile.prod -t NAME:TAG .
docker build --build-arg VERSION=1.0 -t NAME:TAG .
docker build --no-cache -t NAME:TAG .
docker build --target builder -t NAME:builder .
docker build --platform linux/amd64 -t NAME:TAG .
Pull, push, tag
docker pull IMAGE:TAG
docker pull --platform linux/arm64 IMAGE:TAG
docker tag SOURCE:TAG TARGET:TAG
docker push IMAGE:TAG
docker login REGISTRY
docker logout REGISTRY
List and remove images
docker images
docker images --filter "dangling=true"
docker rmi IMAGE
docker rmi -f IMAGE
docker image prune -f
docker image prune -a -f
docker history IMAGE
docker image ls --format "{{.Repository}}:{{.Tag}}\t{{.Size}}"
Volumes
docker volume create VOLUME_NAME
docker volume ls
docker volume inspect VOLUME_NAME
docker volume rm VOLUME_NAME
docker volume prune -f
docker cp CONTAINER:/path/to/file ./local/path
docker cp ./local/file CONTAINER:/path/to/dest
Networking
docker network ls
docker network create NETWORK_NAME
docker network create --driver bridge NETWORK_NAME
docker network create --subnet=172.20.0.0/16 NETWORK_NAME
docker network inspect NETWORK_NAME
docker network connect NETWORK_NAME CONTAINER
docker network disconnect NETWORK_NAME CONTAINER
docker network rm NETWORK_NAME
docker network prune -f
Docker Compose
Compose V2 is a subcommand of docker (not a separate docker-compose binary).
Service lifecycle
docker compose up -d
docker compose up -d SERVICE1 SERVICE2
docker compose up -d --build
docker compose up -d --force-recreate
docker compose -f docker-compose.prod.yml up -d
docker compose down
docker compose down -v
docker compose down --rmi all
docker compose stop
docker compose start
docker compose restart
docker compose restart SERVICE
Build, logs, status
docker compose build
docker compose build --no-cache
docker compose build SERVICE
docker compose logs
docker compose logs -f SERVICE
docker compose logs --tail 50 SERVICE
docker compose ps
docker compose ps -a
docker compose exec SERVICE COMMAND
docker compose exec SERVICE /bin/bash
docker compose run --rm SERVICE COMMAND
docker compose up -d --scale SERVICE=3
docker compose pull
docker compose config
Cleanup and System
docker system df
docker system df -v
docker system prune -f
docker system prune --volumes -f
docker system prune -a -f
docker builder prune -f
docker builder prune --filter "until=24h" -f
Dockerfile Health Check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
--interval: Time between checks (default 30s)
--timeout: Max time for a single check (default 30s)
--start-period: Grace period during startup (default 0s)
--retries: Consecutive failures to report unhealthy (default 3)
Check health status: docker inspect --format '{{.State.Health.Status}}' CONTAINER
Troubleshooting Patterns
Container will not start
docker logs CONTAINER
docker inspect --format '{{.State.ExitCode}}' CONTAINER
docker run -it --entrypoint /bin/sh IMAGE
Out of disk space
docker system df -v
docker system prune -a --volumes -f
Network connectivity issues
docker inspect --format '{{json .NetworkSettings.Networks}}' CONTAINER
docker exec CONTAINER ping OTHER_HOST
docker exec CONTAINER nslookup SERVICE_NAME
Performance: docker stats --no-stream and docker inspect --format '{{.State.OOMKilled}}' CONTAINER