Docker Commands Cheat Sheet
Images, containers, Compose, volumes & cleanup — with examples.
A free, searchable Docker command guide on one long page. Starts with Image vs. Container — the core idea everything else builds on — then covers writing a Dockerfile (FROM, WORKDIR, COPY, RUN, EXPOSE, CMD) with a quick-reference instruction table, images, running & managing containers, logs & inspecting, Docker Compose, volumes & networking, registry & tagging and cleanup/maintenance. Every command has a copy-ready line and a real worked example with terminal output. Search “run container”, “dockerfile” or “prune” to jump straight to it. Runs fully in your browser, no sign-up, no API.
About Docker Commands Cheat Sheet
- Every command explained in plain English — no jargon, with a copy-ready line.
- Real worked examples with terminal output so you know what success looks like.
- Starts with Image vs. Container — the one concept every other command builds on.
- Covers writing a Dockerfile (FROM, WORKDIR, COPY, RUN, CMD) plus a quick-reference instruction table, not just the CLI commands.
- Covers images, containers, logs, Docker Compose, volumes, networking, registries and cleanup.
- Instant search — type "remove container", "port mapping" or "dockerfile" to jump straight to it.
- Copy-paste ready, works the same on Windows, macOS and Linux with Docker installed.
Docker Commands Cheat Sheet features
- Starts with Image vs. Container — the concept every other command builds on
- Covers writing a Dockerfile (FROM, WORKDIR, COPY, RUN, EXPOSE, CMD) with a quick-reference table
- Every command explained in plain English with a copy-ready line
- Real worked examples with terminal output
- Covers images, containers, logs, Docker Compose, volumes, networking and cleanup
- Instant search across every command and section
- 100% free, no sign-up, no API
Best practices
Habits that keep Docker fast and tidy
Docker quietly accumulates disk usage and confusion if you skip these.
TIPAdd a .dockerignore file (works just like .gitignore) so node_modules, .git and build output never get copied into your image — smaller, faster builds.TIPRun docker system df every so often — Docker's build cache and dangling images can quietly eat tens of gigabytes without you noticing.FACTEvery line in a Dockerfile creates a new cached LAYER — reordering so things that change often (like COPY . .) come AFTER things that rarely change (like npm install) makes rebuilds much faster.
docker run --rm automatically removes the container the moment it stops — perfect for one-off test runs you don't want cluttering docker ps -a afterward.
Frequently asked questions
What is the difference between a Docker image and a Docker container?
An image is a read-only, packaged template — the blueprint. A container is a running (or stopped) INSTANCE of that image, like a live process. You can start many containers from the same image, each isolated from the others.
How do I write a Dockerfile?
Start with FROM to pick a base image (like FROM node:20), WORKDIR to set the folder to work in, COPY to bring your files in, RUN to install dependencies at build time, EXPOSE to document the port your app uses, and CMD to set the command that runs when the container starts. Then build it with docker build -t my-app .
What is the difference between CMD and RUN in a Dockerfile?
RUN executes a command while the image is being BUILT, and its result (like installed packages) is saved permanently into the image. CMD sets the default command that runs when a container STARTS from that image, and can be overridden at docker run time.
How do I run a Docker container?
Use docker run — for example docker run -d -p 8080:80 --name web nginx runs an nginx container in the background (-d), maps port 8080 on your machine to port 80 inside the container (-p), and names it "web".
How do I see which containers are running?
Run docker ps to see currently running containers, or docker ps -a to also include stopped ones.
How do I stop and remove a Docker container?
Run docker stop <container> to stop it gracefully, then docker rm <container> to delete it. Use docker rm -f <container> to force-remove one that's still running.
How do I view a container's logs?
Run docker logs <container> to see everything it has printed, or docker logs -f <container> to keep watching new log lines live, similar to tail -f.
How do I get a shell inside a running container?
Run docker exec -it <container> bash to open an interactive terminal inside the container — useful for debugging or inspecting files directly.
What does docker compose up do?
It reads docker-compose.yml in the current folder and builds/starts every service it defines — a web app, a database, a cache, all in one command. Add -d to run everything in the background, and --build to force a fresh image rebuild first.
How do I make data survive a container being removed?
Mount a volume with -v — either a folder on your machine (docker run -v ./data:/app/data image) or a Docker-managed named volume (docker volume create db-data, then -v db-data:/var/lib/mysql). Without a volume, any data written inside a container is lost when it's removed.
How do I free up disk space Docker is using?
Run docker system df to see what's taking the space, then docker container prune to remove old stopped containers, docker image prune -a to remove unused images, or docker system prune -a --volumes to clean up everything at once.
How do I push my image to Docker Hub?
First log in with docker login, tag your image with your username (docker tag my-app username/my-app:v1.0), then push it with docker push username/my-app:v1.0.
What does the -p flag mean in docker run?
-p host-port:container-port publishes a port, connecting a port on your machine to a port inside the container. The number on the left is what YOU connect to; the number on the right is what the app inside the container is actually listening on.
How do containers talk to each other?
Put them on the same custom Docker network with docker network create <name>, then run each container with --network <name>. Containers on the same network can reach each other by their container name, like a hostname.
Is this Docker commands cheat sheet free to use?
Yes — it's 100% free with no sign-up, no login and no limits. Every command, example and the search box work fully in your browser.
Related tools — Guides & Tutorials
- Git & GitHub Guide — Clone, commit, push, branch & merge — every Git command with examples.
- Keyboard Shortcuts Guide (Windows & Mac) — Every shortcut for copy/paste, browsers, Word & Excel — Windows & Mac side by side.
- Regex Cheat Sheet — Syntax Reference — Every regex symbol, quantifier, group & flag explained with copy-ready patterns.
- SQL Cheat Sheet — Syntax & Query Reference — SELECT to window functions, transactions & indexes — with copy-ready queries.
- Python Basics Cheat Sheet — Syntax Reference — Variables, strings, lists, loops & functions — every Python basic with copy-ready code.
- Excel Cheat Sheet — Every essential Excel shortcut & top formula on one page.
- Excel Guide — How Excel works — the fundamentals, explained simply.
- Beginner Excel — Everyday Excel skills — with step-by-step examples.
- Advanced Excel — Lookups, dropdowns, duplicates & PivotTables — with examples.
- Master Excel — Dynamic arrays, Power Query, macros & dashboards.
- Google Sheets Cheat Sheet — Every formula — text, math, lookups, dates & QUERY — with examples.
- VS Code Shortcuts Cheat Sheet — Every keyboard shortcut — editing, multi-cursor, search & debugging.
- Linux / Bash Commands Cheat Sheet — Every terminal command — files, permissions, processes & networking.
- Vim Cheat Sheet — Movement, editing, search & how to actually save and quit.