docker pull <image>
Download an image from registry
docker images
List local images
docker rmi <image>
Remove an image
docker image prune -a
Remove all unused images
docker build -t name:tag .
Build image from Dockerfile
docker build --no-cache -t name .
Build without cache
docker tag src:latest user/src:1.0
Tag an image
docker push user/image:tag
Push image to registry
docker history <image>
Show image layer history
docker save -o backup.tar image
Save image to tar file
docker load -i backup.tar
Load image from tar file
docker run <image>
Run a container from image
docker run -d --name web nginx
Run detached with name
docker run -it ubuntu bash
Run interactive with terminal
docker run -p 8080:80 nginx
Map host port to container port
docker run -v /host:/container image
Mount host directory as volume
docker run --rm image
Auto-remove on exit
docker run -e KEY=value image
Set environment variable
docker run --env-file .env image
Load env from file
docker ps
List running containers
docker ps -a
List all containers (incl. stopped)
docker stop <container>
Stop a running container
docker start <container>
Start a stopped container
docker restart <container>
Restart container
docker rm <container>
Remove a stopped container
docker rm -f <container>
Force-remove running container
docker container prune
Remove all stopped containers
docker exec -it <container> bash
Open shell in container
docker logs <container>
Show container logs
docker logs -f --tail 100 <container>
Follow last 100 log lines
docker inspect <container>
Show detailed info (JSON)
docker stats
Live resource usage per container
docker cp file container:/path
Copy file into container
FROM node:20-alpine
Base image
WORKDIR /app
Set working directory
COPY . .
Copy files into image
COPY package*.json ./
Copy matching pattern
RUN npm install
Run command at build time
ENV NODE_ENV=production
Set environment variable
EXPOSE 3000
Document listening port
CMD ["node", "server.js"]
Default container command
ENTRYPOINT ["/app/start.sh"]
Fixed entrypoint command
ARG VERSION=1.0
Build-time argument
USER node
Switch user (security)
HEALTHCHECK CMD curl -f http://localhost/ || exit 1
Container healthcheck
docker compose up
Start services from compose file
docker compose up -d
Start detached
docker compose down
Stop and remove services
docker compose down -v
Stop and remove volumes too
docker compose ps
List compose services
docker compose logs -f service
Follow logs for one service
docker compose build
(Re)build all services
docker compose exec service bash
Shell into a compose service
docker compose restart service
Restart one service
docker network ls
List networks
docker network create mynet
Create a network
docker run --network mynet image
Attach container to network
docker volume ls
List volumes
docker volume create mydata
Create named volume
docker volume prune
Remove unused volumes
docker system prune -a
Remove all unused data (careful)
Docker Cheat Sheet — Containers, Images, Compose, Volumes & Networks
Docker shipped in 2013 and turned containers from a Linux kernel curiosity into the default way to package server software. The cheatsheet below covers 60+ commands across images, containers, Dockerfile instructions, Compose, networks, and volumes. Most trouble in everyday Docker work does not come from forgetting commands. It comes from quirks that look ordinary until they bite. A `COPY . .` placed before `RUN npm install` invalidates the cached install layer on every source-file change, turning a five-second rebuild into a five-minute one — the fix is to `COPY package*.json ./` and run install before copying the rest. A bind mount with `-v /host:/container` completely hides whatever the image baked into that path, which is why a freshly built image suddenly looks empty in dev. `docker system prune -a` removes every image not currently used by a running container, not just dangling ones, so a stopped container's image vanishes with it. These are the snippets pulled up while debugging exactly that — the right `COPY` order, the right Compose flag, the right log tail — without rereading the Docker docs from page one each time.
Common pitfalls in Docker
A few patterns earn their place near the top of any Dockerfile. Order instructions from least to most frequently changing so the build cache stays warm: base image, then OS packages, then dependency manifests (`package*.json`, `requirements.txt`, `go.mod`), then `RUN install`, and only after that the application source. `CMD` and `ENTRYPOINT` look similar but differ at runtime — `CMD` is the default command and gets fully replaced by anything passed after `docker run image`, while `ENTRYPOINT` is fixed and the runtime arguments become its parameters, which is what most production images actually want. A `.dockerignore` file in the build context is what stops `node_modules`, `.git`, and build artefacts from being copied into every layer; without it, the image bloats and cache invalidation gets unpredictable. `EXPOSE` documents the listening port but does not publish it — only `-p` or Compose `ports:` makes the port reachable from the host. The cheatsheet groups all of this into Images, Containers, Dockerfile, Compose, and Networks so the right section is one click away.
- 60+ Docker commands organized by workflow
- Image management (pull, build, push, tag)
- Container lifecycle (run, exec, logs, stats)
- Dockerfile instruction reference
- docker compose commands
- Networks and volumes
Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).
By Marco B. ·