2 min read · updated 18 Nov 2026
Docker Basics Cheat Sheet
Core Docker concepts and the most common commands for building, running, and managing containers
Core Concepts
| Term | What it means |
|---|---|
| Image | A read-only template that describes a container's filesystem and configuration |
| Container | A running instance of an image, isolated from the host |
| Dockerfile | A text file with instructions to build an image |
| Registry | A storage service for images (Docker Hub is the public default) |
| Volume | A persistent storage area that survives container restarts |
| Network | An isolated virtual network containers can join to communicate |
Building Images
| Command | What it does |
|---|---|
docker build -t name:tag . | Builds an image from the Dockerfile in the current directory |
docker build -f path/Dockerfile . | Builds using a Dockerfile at a specific path |
docker images | Lists all local images |
docker rmi <image> | Removes an image |
docker pull <image> | Downloads an image from the registry |
docker push <image> | Uploads an image to the registry |
Running Containers
| Command | What it does |
|---|---|
docker run <image> | Creates and starts a container |
docker run -it <image> | Runs with interactive terminal |
docker run -d <image> | Runs in the background (detached) |
docker run -p 8080:80 <image> | Maps host port 8080 to container port 80 |
docker run --name myapp <image> | Assigns a name to the container |
docker run -v /host:/container <image> | Mounts a host directory as a volume |
docker run --rm <image> | Removes the container when it exits |
Managing Containers
| Command | What it does |
|---|---|
docker ps | Lists running containers |
docker ps -a | Lists all containers, including stopped ones |
docker stop <container> | Gracefully stops a running container |
docker start <container> | Starts a stopped container |
docker restart <container> | Stops and starts a container |
docker rm <container> | Removes a stopped container |
docker rm -f <container> | Force-removes a running container |
Inspecting and Debugging
| Command | What it does |
|---|---|
docker logs <container> | Shows a container's output |
docker logs -f <container> | Follows the output in real time |
docker exec -it <container> sh | Opens a shell inside a running container |
docker inspect <container> | Shows detailed container configuration as JSON |
docker stats | Live resource usage for running containers |
Volumes and Networks
| Command | What it does |
|---|---|
docker volume create <name> | Creates a named volume |
docker volume ls | Lists all volumes |
docker volume rm <name> | Removes a volume |
docker network create <name> | Creates a network |
docker network ls | Lists networks |
docker run --network <name> <image> | Runs a container on a specific network |
Minimal Dockerfile Example
FROM python:3-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "app.py"]Cleanup
| Command | What it does |
|---|---|
docker system prune | Removes stopped containers, unused images, and networks |
docker system prune -a | Also removes images not used by any container |
Warning: docker system prune -a deletes every image that no container is using. Check docker images first, because you will have to download them again.
More cheat sheets
Not sure your computer can run a model? Use the will-it-run checker.

