Docker Cheatsheet
Essential Docker commands for managing containers, images, volumes, and networks.
Container Management
| Command | Description |
|---|---|
| docker ps | List running containers |
| docker ps -a | List all containers (including stopped) |
| docker run <image> | Run a container from an image |
| docker run -d <image> | Run a container in detached mode |
| docker run -it <image> /bin/bash | Run interactively with shell |
| docker run -p 8080:80 <image> | Map host port to container port |
| docker start <container> | Start a stopped container |
| docker stop <container> | Stop a running container |
| docker restart <container> | Restart a container |
| docker rm <container> | Remove a container |
| docker rm -f <container> | Force remove a running container |
Image Management
| Command | Description |
|---|---|
| docker images | List local images |
| docker pull <image> | Pull an image from a registry |
| docker build -t <name> . | Build an image from a Dockerfile |
| docker rmi <image> | Remove an image |
| docker tag <src> <target> | Tag an image |
| docker push <image> | Push an image to a registry |
| docker image prune | Remove unused images |
Logs & Debugging
| Command | Description |
|---|---|
| docker logs <container> | View container logs |
| docker logs -f <container> | Follow log output |
| docker exec -it <container> /bin/sh | Run a command inside a running container |
| docker inspect <container> | View detailed container info in JSON |
| docker stats | Show live resource usage of containers |
| docker top <container> | Show running processes in a container |
Volumes & Data
| Command | Description |
|---|---|
| docker volume ls | List volumes |
| docker volume create <name> | Create a volume |
| docker volume rm <name> | Remove a volume |
| docker volume prune | Remove all unused volumes |
| docker run -v <host>:<container> <image> | Bind mount a host path |
| docker run -v <vol>:<container> <image> | Mount a named volume |
Networks
| Command | Description |
|---|---|
| docker network ls | List networks |
| docker network create <name> | Create a network |
| docker network rm <name> | Remove a network |
| docker network connect <net> <container> | Connect a container to a network |
| docker network disconnect <net> <container> | Disconnect a container from a network |
Docker Compose
| Command | Description |
|---|---|
| docker compose up | Create and start containers |
| docker compose up -d | Start in detached mode |
| docker compose down | Stop and remove containers, networks |
| docker compose down -v | Also remove volumes |
| docker compose logs | View logs from all services |
| docker compose ps | List containers managed by Compose |
| docker compose build | Build or rebuild services |
| docker compose restart | Restart all services |
Cleanup
| Command | Description |
|---|---|
| docker system prune | Remove unused data (containers, networks, images) |
| docker system prune -a | Remove all unused data including unused images |
| docker container prune | Remove all stopped containers |
| docker image prune -a | Remove all unused images |