Docker Cheatsheet
Build, run, and ship containers faster with the Docker commands you actually use.
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 -fKnowledge is power.