SadServers
  • Scenarios
  • Labs
    All Labs Linux & Bash Web Servers Databases Data Processing Docker Kubernetes CI/CD Infrastructure as Code Tooling / Applications
  • Dashboard
  • Solutions
    For Individuals For Businesses
  • Ranking
  • Newsletter
  • Documentation
    FAQ Support Pro Accounts Pro+ Accounts Business Accounts Gift API CLI/TUI Privacy Troubleshooting Interviews
  • Blog
  • Pricing
  • Gift
    Gift Purchase Gift Redeem
  • About
Log In - Sign Up
  1. Labs
  2. Docker
  3. Cheatsheet

Guide

Concepts and learning path

Troubleshooting

Failure modes and fixes

Cheatsheet

Commands to keep handy

Docker cheatsheet

Images

CommandDescription
docker pull nginx:1.25Download image from registry
docker imagesList local images
docker build -t myapp:1.0 .Build from Dockerfile in cwd
docker rmi image_idRemove image
docker history myapp:1.0Image layer history
docker inspect nginx:1.25Image metadata (JSON)

Containers — run and lifecycle

CommandDescription
docker run -d --name web -p 8080:80 nginxDetached run, publish port
docker run -it --rm alpine shInteractive shell, remove on exit
docker psRunning containers
docker ps -aAll containers (including stopped)
docker stop webGraceful stop (SIGTERM)
docker start webStart stopped container
docker rm webRemove container
docker restart webRestart container

Exec, logs, inspect

CommandDescription
docker logs -f webFollow container logs
docker logs --tail 100 webLast 100 log lines
docker exec -it web shShell inside running container
docker exec web cat /etc/hostsRun single command
docker inspect webFull container config/state
docker top webProcesses inside container

Volumes and mounts

CommandDescription
docker volume lsList volumes
docker volume inspect volVolume mountpoint on host
docker run -v /host/data:/data myappBind mount
docker run -v myvol:/data myappNamed volume

Networking

CommandDescription
docker network lsList networks
docker network inspect bridgeNetwork details and IPs
docker port webPublished port mappings
ss -tlnp | grep 8080Confirm host port listening

Compose

docker compose up -d # Start stack detached docker compose ps # Service status docker compose logs -f web # Follow service logs docker compose down # Stop and remove containers docker compose build # Rebuild images docker compose exec web sh # Shell in service container

Daemon and disk

CommandDescription
systemctl status dockerDaemon status
docker infoDaemon summary, storage driver
docker system dfDisk use: images, containers, volumes
docker system df -vPer-object size breakdown

Cleanup and prune

Run docker system df first. Prune removes data you may still need — especially volumes. Add -f to skip the confirmation prompt.

CommandDescription
docker container pruneRemove all stopped containers
docker rm CONTAINERRemove one container (must be stopped)
docker rm -f CONTAINERForce-remove running container
docker image pruneRemove dangling images (<none> tags)
docker image prune -aRemove images not used by any container
docker rmi IMAGERemove one image by name or ID
docker volume pruneRemove volumes not attached to a container
docker volume rm VOLRemove one named volume
docker network pruneRemove unused custom networks
docker builder pruneClear build cache (BuildKit)
docker system pruneStopped containers + dangling images + unused networks
docker system prune -aAbove + all unused images
docker system prune -a --volumesAbove + unused volumes (destructive)
docker compose down -vStop stack and remove compose volumes
# Typical cleanup order (safest first) docker container prune -f # exited / stopped containers docker image prune -f # dangling build layers docker image prune -a -f # images no container references docker volume prune -f # only if data is disposable docker network prune -f docker builder prune -f # stale build cache # List before bulk delete docker ps -a --filter status=exited docker images -f dangling=true docker volume ls -f dangling=true

Useful inspect filters

docker inspect web | jq -r '.State.ExitCode' docker inspect web | jq -r '.State.Status' docker inspect web | jq -r '.NetworkSettings.Networks[].IPAddress' docker inspect web | jq '.Config.Cmd'

Pro tips

  • Container exited? Check docker logs and docker inspect .State.ExitCode first
  • -p 8080:80 maps host:container — swapping them is a common mistake
  • PID 1 must handle signals — bare shell scripts may ignore SIGTERM from docker stop
  • Pin image tags in production — latest changes without warning
  • Disk full? docker system df -v then container prune, image prune -a, volume prune — see Cleanup section

Practice scenarios

Hands-on Docker scenarios on live Linux VMs: docker

SadServersSadServers

Real-world Linux and DevOps scenarios for hands-on learning and technical assessment.

Uptime Robot ratio (30 days)
Product
  • Scenarios
  • For Individuals
  • For Businesses
  • Pricing
Resources
  • FAQ
  • Blog
  • Newsletter
Company
  • About Us
  • Support
  • Privacy Policy
  • Terms of Service
  • Contact
Connect With Us
info@sadservers.com

Made in Canada 🇨🇦
Updated: 2026-06-13 16:06 UTC – 2d2950a