Docker Cheatsheet and Reference
A comprehensive command reference for Docker, organized by task. Use this module as a quick-lookup guide during daily operations.
- Container Lifecycle
- Images
- Inspect & Debug
- Network & Volumes
- Compose
- Cleanup
| Command | Description |
|---|---|
docker run -d --name app IMAGE | Start container in background |
docker run --rm -it IMAGE sh | Start temporary interactive container |
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker stop CONTAINER | Gracefully stop (SIGTERM → SIGKILL after timeout) |
docker kill CONTAINER | Force stop immediately (SIGKILL) |
docker rm CONTAINER | Remove a stopped container |
docker rm -f CONTAINER | Force remove a running container |
docker restart CONTAINER | Stop and start a container |
docker rename OLD NEW | Rename a container |
| Command | Description |
|---|---|
docker build -t NAME:TAG . | Build image from Dockerfile |
docker build --no-cache -t NAME . | Build without layer cache |
docker images | List local images |
docker pull NAME:TAG | Download image from registry |
docker push NAME:TAG | Upload image to registry |
docker tag SOURCE TARGET | Create a new tag for an image |
docker rmi IMAGE | Delete a local image |
docker image prune | Delete dangling images (<none>) |
docker image prune -a | Delete all unused images |
docker history IMAGE | Show image layer history |
docker image inspect IMAGE | Show image metadata as JSON |
| Command | Description |
|---|---|
docker logs CONTAINER | View container logs |
docker logs -f --tail=100 CONTAINER | Follow last 100 lines live |
docker logs --since=15m CONTAINER | Logs from last 15 minutes |
docker exec -it CONTAINER sh | Open a shell inside a container |
docker exec CONTAINER CMD | Run a single command inside container |
docker inspect CONTAINER | Full JSON metadata |
docker stats | Live CPU/memory/network usage |
docker top CONTAINER | Show running processes |
docker cp CONTAINER:SRC DEST | Copy files from container |
docker cp SRC CONTAINER:DEST | Copy files into container |
docker diff CONTAINER | Show filesystem changes |
| Command | Description |
|---|---|
docker network ls | List networks |
docker network create NAME | Create a user-defined network |
docker network inspect NAME | View network details and members |
docker network connect NET CONTAINER | Attach container to network |
docker network disconnect NET CONTAINER | Detach container from network |
docker network rm NAME | Remove a network |
docker volume ls | List all volumes |
docker volume create NAME | Create a named volume |
docker volume inspect NAME | View volume details |
docker volume rm NAME | Remove a volume (data loss!) |
docker port CONTAINER | Show port mappings |
| Command | Description |
|---|---|
docker compose up -d | Start stack in background |
docker compose down | Stop and remove stack |
docker compose down -v | Stop, remove stack AND volumes |
docker compose ps | List stack services |
docker compose logs -f | Follow all service logs |
docker compose logs -f SERVICE | Follow one service's logs |
docker compose pull | Pull latest images for all services |
docker compose build | Rebuild service images |
docker compose restart SERVICE | Restart a service |
docker compose config | Validate and render merged config |
docker compose exec SERVICE sh | Shell into a running service |
| Command | Description | Risk |
|---|---|---|
docker image prune | Remove dangling images | Safe |
docker container prune | Remove stopped containers | Safe |
docker network prune | Remove unused networks | Safe |
docker builder prune | Remove build cache | Safe |
docker volume prune | Remove unused volumes | ⚠ Data loss |
docker system prune | Remove containers, images, networks, cache | ⚠ Check first |
docker system prune -a --volumes | Remove everything unused | ❌ Dangerous |
docker system df | Check what's using disk space | Read-only |
docker system df -v | Detailed disk usage breakdown | Read-only |
Detailed References
For expanded command explanations with examples:
| Reference Page | What It Covers |
|---|---|
| Core Engine Commands | docker version, info, system df, events, diagnostics |
| Image and Build Commands | docker build, tag, push, multi-stage, .dockerignore |
| Container Ops Commands | docker run, exec, logs, inspect, debugging workflows |
| Network and Volume Commands | Network creation, DNS testing, volume management, backup |
| Compose Commands | docker compose lifecycle, multi-file, production workflows |