Last updated: April 12, 2026
Docker Commands Cheatsheet
Quick Answer
This cheatsheet covers 35 essential Docker commands for managing containers, images, volumes, and networks. Includes Docker Compose commands for multi-container applications.
Containers
| Command | Description |
|---|---|
| docker run <image> | Create and start a container from an image docker run nginx |
| docker run -d <image> | Run a container in detached (background) mode docker run -d nginx |
| docker run -p <host>:<container> <image> | Map a host port to a container port docker run -p 8080:80 nginx |
| docker run -v <host>:<container> <image> | Mount a host directory as a volume docker run -v ./data:/app/data myapp |
| docker run --name <name> <image> | Assign a name to the container docker run --name web nginx |
| docker run --rm <image> | Automatically remove the container when it exits |
| docker run -it <image> /bin/sh | Run a container with an interactive shell docker run -it alpine /bin/sh |
| docker ps | List running containers |
| docker ps -a | List all containers (including stopped) |
| docker stop <container> | Gracefully stop a running container docker stop web |
| docker start <container> | Start a stopped container docker start web |
| docker restart <container> | Restart a container |
| docker rm <container> | Remove a stopped container docker rm web |
| docker rm -f <container> | Force remove a running container |
| docker exec -it <container> /bin/sh | Open an interactive shell in a running container docker exec -it web /bin/sh |
| docker logs <container> | View container logs docker logs web |
| docker logs -f <container> | Follow (stream) container logs in real-time |
| docker inspect <container> | View detailed container configuration as JSON |
Images
| Command | Description |
|---|---|
| docker build -t <name> . | Build an image from a Dockerfile in the current directory docker build -t myapp:latest . |
| docker images | List all local images |
| docker pull <image> | Download an image from a registry docker pull node:20-alpine |
| docker push <image> | Push an image to a registry docker push myrepo/myapp:latest |
| docker rmi <image> | Remove a local image docker rmi myapp:latest |
| docker image prune | Remove unused (dangling) images |
Volumes
| Command | Description |
|---|---|
| docker volume create <name> | Create a named volume docker volume create pgdata |
| docker volume ls | List all volumes |
| docker volume rm <name> | Remove a volume |
Networks
| Command | Description |
|---|---|
| docker network create <name> | Create a user-defined network docker network create app-net |
| docker network ls | List all networks |
| docker network connect <network> <container> | Connect a container to a network |
Compose
| Command | Description |
|---|---|
| docker compose up | Start services defined in docker-compose.yml |
| docker compose up -d | Start services in detached mode |
| docker compose down | Stop and remove containers, networks defined in compose |
| docker compose logs -f | Follow logs for all compose services |
Cleanup
| Command | Description |
|---|---|
| docker system prune -a | Remove all unused containers, images, networks, and volumes |
Frequently Asked Questions
More Cheatsheets
Git Commands Cheatsheet
This cheatsheet covers the 40 most essential Git commands grouped by workflow: setup, staging, branc...
Linux Commands Cheatsheet
This cheatsheet covers 40 essential Linux/Unix commands for daily development: file navigation, text...
HTTP Status Codes Cheatsheet
HTTP status codes are 3-digit numbers returned by servers. 1xx = informational, 2xx = success, 3xx =...
Regex Syntax Cheatsheet
This cheatsheet covers essential regex syntax: character classes, quantifiers, anchors, groups, and ...