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 / CodeDescription
docker build -t app .Build an image from Dockerfile.
docker imagesList local images.
docker pull <image>Pull an image from a registry.
docker rmi <image>Remove an image.

Containers

Key / CodeDescription
docker run -it <image> shRun interactively with a shell.
docker run -d -p 3000:3000 <image>Run in background with port mapping.
docker psList running containers.
docker ps -aList all containers.
docker stop <id>Stop a container.
docker rm <id>Remove a container.

Volumes & Files

Key / CodeDescription
docker volume lsList volumes.
docker run -v data:/app/data <image>Mount a named volume.
docker cp <id>:/app/log.txt .Copy file from container.

Networking

Key / CodeDescription
docker network lsList networks.
docker network create devnetCreate 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 down

Cleanup

Keep your local environment lean.

docker system prune -f
# remove unused images only
docker image prune -f

Common 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

Knowledge is power.