How to use the Docker Cheat Sheet
- Type your own values (image, container, ports, service) in the boxes at the top — every example on the page updates instantly.
- Search or jump to a section to find the command you need.
- Click Copy to copy a ready-to-run line, or Copy section for a commented block.
- Commands marked destructive delete or overwrite data — read the note before running them.
Images, containers, volumes and networks
An image is a packaged filesystem and start command, built from a Dockerfile. A container is a running copy of an image. Anything a container writes disappears when it is removed, unless it goes into a volume. Containers on the same user-defined network reach each other by name, which is how Compose services talk to their database.
Reading -p and -v
Both flags are host:container. -p 8080:3000 means “requests to port 8080 on my machine go to port 3000 in the container”. -v app-data:/data mounts the named volume app-data at /data; -v "$(pwd)":/app mounts your current folder instead, which is how you get live code reloading in development.
Keeping images small and builds fast
- Start from slim bases such as
-alpineor-slim, and use multi-stage builds so compilers don’t ship to production. - Copy dependency files and install before copying the rest of the code, so the install layer stays cached.
- Add a
.dockerignorefornode_modules,.gitand build output.
Write Compose files with the Docker Compose generator, and set up CI with the GitHub Actions generator.
Tools that pair well with the Docker Cheat Sheet
- Linux Commands Cheat Sheet — The Linux and bash commands developers use on servers and laptops — files, search, permissions, processes, logs, networking and SSH.
- Git Cheat Sheet — Every Git command you use day to day — and the ones you need when something goes wrong — explained in one line.
- Nginx Config Generator — Choose what Nginx should do — serve a static site or SPA, proxy to a Node/Python app, or run PHP — and tick the extras.
- AI Prompts for Developers — Battle-tested prompts for the coding tasks you do every day — debugging, reviews, tests, refactoring, SQL, commit messages and documentation.
Frequently asked questions
What is the difference between an image and a container?
How do I free up disk space used by Docker?
docker system df, then remove build cache with docker builder prune and unused images with docker image prune -a. docker system prune removes more at once — read what it deletes first.Is it docker compose or docker-compose?
docker compose (with a space). It is Compose v2, built into the Docker CLI. The separate docker-compose v1 tool is deprecated.Why can’t my containers reach each other?
docker network create) or the same Compose project, then use the service or container name as the hostname.