Docker Cheatsheet
Build, run, and ship containers faster with the Docker commands you actually use.
When This Cheatsheet Helps Most
This page is most useful when you need to build an image, inspect a failing container, mount local files, or clean up a development machine that is full of unused images and stopped containers.
Images
| Key / Code | Description |
|---|---|
| docker build -t app . | Build an image from Dockerfile. |
| docker images | List local images. |
| docker pull <image> | Pull an image from a registry. |
| docker rmi <image> | Remove an image. |
Containers
| Key / Code | Description |
|---|---|
| docker run -it <image> sh | Run interactively with a shell. |
| docker run -d -p 3000:3000 <image> | Run in background with port mapping. |
| docker ps | List running containers. |
| docker ps -a | List all containers. |
| docker stop <id> | Stop a container. |
| docker rm <id> | Remove a container. |
Volumes & Files
| Key / Code | Description |
|---|---|
| docker volume ls | List volumes. |
| docker run -v data:/app/data <image> | Mount a named volume. |
| docker cp <id>:/app/log.txt . | Copy file from container. |
Networking
| Key / Code | Description |
|---|---|
| docker network ls | List networks. |
| docker network create devnet | Create a network. |
| docker run --network devnet <image> | Attach a container to a network. |
Compose
Run multi-container apps with one command.
docker compose up -d
# stop
docker compose downCleanup
Keep your local environment lean.
docker system prune -f
# remove unused images only
docker image prune -fCommon Docker Mistakes
A frequent mistake is debugging the image when the real problem is the container runtime configuration, such as the wrong environment variable, missing port mapping, or an unexpected bind mount overriding files inside the image.
Related
Move from single-container workflows to orchestration concepts and common kubectl tasks.
Debug browser-side API failures when your backend runs in Docker or behind a local proxy.
Connect to remote hosts when your containers are not only running locally.
Schedule recurring jobs, cleanup scripts, and periodic container tasks safely.