Docker Cheat Sheet
A reference for everyday Docker, building and tagging images, running and managing containers, ports and volumes, system cleanup, and Docker Compose.
The Docker commands you need to build images and run containers. Replace
IMAGE, CONTAINER, and TAG with your own values.
Images
| Command | What it does |
|---|---|
docker pull IMAGE | Download an image from a registry |
docker images | List local images |
docker build -t name:TAG . | Build an image from a Dockerfile |
docker rmi IMAGE | Remove an image |
docker tag SRC name:TAG | Tag an image for pushing |
docker push name:TAG | Upload an image to a registry |
Running containers
| Command | What it does |
|---|---|
docker run -it IMAGE bash | Run a container with an interactive shell |
docker run -d -p 8080:80 IMAGE | Run detached, mapping host:container ports |
docker run --rm IMAGE | Run and auto-remove when it exits |
docker run -v /host:/app IMAGE | Mount a host folder into the container |
docker run -e KEY=val IMAGE | Set an environment variable |
Managing containers
| Command | What it does |
|---|---|
docker ps | List running containers (-a for all) |
docker stop CONTAINER | Stop a running container |
docker start CONTAINER | Start a stopped container |
docker rm CONTAINER | Remove a stopped container |
docker exec -it CONTAINER bash | Open a shell in a running container |
docker logs -f CONTAINER | View and follow container output |
System & cleanup
| Command | What it does |
|---|---|
docker system df | Show disk usage by images/containers/volumes |
docker system prune | Remove unused data (-a = all unused images) |
docker volume ls | List volumes |
docker network ls | List networks |
Docker Compose
| Command | What it does |
|---|---|
docker compose up -d | Start all services from compose.yaml |
docker compose down | Stop and remove the services |
docker compose ps | List the project's containers |
docker compose logs -f | Follow logs from all services |
docker compose build | Build / rebuild service images |
A container is a running instance of an image. Images are layered and cached, so ordering your Dockerfile from least- to most-frequently changed (dependencies before source) makes rebuilds much faster.
What this does
A Docker cheat sheet covers building and tagging images, running and managing containers, ports and volumes, cleanup, and Docker Compose.
How to use it
- Browse by section.
- Find the command you need.
- Copy it with one tap.
- Replace image and container names.
Example
docker ps lists the containers currently running.
Sources & methodology
Last updated .
Frequently asked questions
What’s the difference between an image and a container?
An image is a read-only template; a container is a running (or stopped) instance of an image. You can start many containers from the same image.
How do I free up disk space?
Run docker system prune to remove stopped containers and unused data, or docker system prune -a to also remove all unused images. Check usage first with docker system df.
How do I get a shell inside a running container?
Use docker exec -it CONTAINER bash (or sh if bash is not installed) to open an interactive shell.
Related tools
Git Cheat Sheet
The Git commands you use every day, setup, the add/commit/push workflow, branching and merging, working with remotes, and undoing mistakes safely.
Vim Cheat Sheet
A reference for the Vim editor, modes, moving around, editing, search and replace, and saving or quitting, including the escape hatch for when you are stuck.
Regex Cheat Sheet
A regular-expression reference, character classes, anchors, quantifiers, groups and alternation, lookarounds, common ready-made patterns, and flags.
SQL Cheat Sheet
A reference for standard SQL, querying with SELECT, filtering with WHERE, aggregates and GROUP BY, joining tables, and modifying data and schema.