New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsDockerDocker
FreeSheet 01 of 11

Docker Basics & Installation

A comprehensive developer cheatsheet covering Docker fundamentals and installation, featuring essential CLI commands and operational workflows for Docker architecture, versioning, system inspection, and resource management.

What is Docker?

Docker is a platform for developing, shipping, and running applications in containers.

Docker Architecture

ComponentPurpose
Docker DaemonBackground service that manages containers
Docker ClientCLI tool for interacting with Docker daemon
Docker RegistryRepository for Docker images (e.g., Docker Hub)
ImagesRead-only templates for containers
ContainersRunning instances of images

Key Concepts

ConceptDescription
ImageA lightweight, standalone, executable package
ContainerA running instance of an image
DockerfileInstructions to build an image
VolumePersistent data storage for containers
NetworkConnectivity between containers

Docker Installation

Linux (Ubuntu/Debian)

bash
# Update package list
$ sudo apt update

# Install Docker
$ sudo apt install docker.io -y

# Start Docker service
$ sudo systemctl start docker
$ sudo systemctl enable docker

# Verify installation
$ docker --version

Linux (RHEL/CentOS/Fedora)

bash
# Install Docker
$ sudo yum install docker -y

# Start Docker service
$ sudo systemctl start docker
$ sudo systemctl enable docker

# Verify installation
$ docker --version

macOS (Homebrew)

bash
$ brew install docker
$ brew install docker-compose

macOS (Docker Desktop)

Download from: https://www.docker.com/products/docker-desktop

Windows (Docker Desktop)

Download from: https://www.docker.com/products/docker-desktop

Run Docker Without Sudo (Linux)

bash
# Add user to docker group
$ sudo usermod -aG docker $USER

# Logout and login again, or run:
$ newgrp docker

docker version — Show Version Info

Shows Docker client and server versions.

Basic Usage

bash
$ docker version
Client:
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:01:05 2023
 OS/Arch:           linux/amd64
 Context:           default

Server:
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:01:05 2023
  OS/Arch:          linux/amd64
  Experimental:     false

Common Flags

FlagPurpose
--formatFormat output using Go template
-fSame as --format

Examples

Show only client version:

bash
$ docker version --format '{{.Client.Version}}'
24.0.7

Show only server version:

bash
$ docker version --format '{{.Server.Version}}'
24.0.7

docker info — Show System Info

Displays system-wide Docker information.

Basic Usage

bash
$ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
  compose: Docker Compose (Docker Inc.)

Server:
 Containers: 5
  Running: 3
  Paused: 0
  Stopped: 2
 Images: 12
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Authorization: rhel-push-plugin
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 8c6eaffaaf3c46b6649029417a8b7730b6c5d2cd
 runc version: v1.1.5-0-gf19387a
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 5.15.0-91-generic
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.6GiB
 Name: ubuntu-server
 ID: 1234-5678-9012-3456-7890
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Common Use Cases

Check if Docker is running:

bash
$ docker info | grep "Server Version"

Check disk usage:

bash
$ docker info | grep "Docker Root Dir"

docker help — Get Command Help

Shows help information for Docker commands.

Basic Usage

bash
$ docker --help
Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Common Commands:
  run         Create and run a new container from an image
  exec        Execute a command in a running container
  ps          List containers
  build       Build an image from a Dockerfile
  pull        Download an image from a registry
  push        Upload an image to a registry
  images      List images
  login       Log in to a registry
  logout      Log out from a registry
  search      Search Docker Hub for images
  version     Show the Docker version information
  info        Display system-wide information

Management Commands:
  container   Manage containers
  image       Manage images
  network     Manage networks
  volume      Manage volumes
  system      Manage Docker

Help for Specific Commands

bash
$ docker run --help
$ docker ps --help
$ docker images --help

docker system — Manage Docker

Manages Docker system resources.

Subcommands

CommandPurpose
system dfShow disk usage
system eventsShow real-time events
system infoShow system info (same as docker info)
system pruneRemove unused data

docker system df — Show Disk Usage

bash
$ docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          12        5         2.345GB   1.234GB (52%)
Containers      5         3         567MB     234MB (41%)
Local Volumes   8         4         1.2GB     678MB (56%)
Build Cache     0         0         0B        0B

Show detailed disk usage:

bash
$ docker system df -v

docker system prune — Remove Unused Data

bash
$ docker system prune
WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N] y

Deleted Containers:
abc123...
def456...

Deleted Images:
untagged: nginx:latest
deleted: sha256:abc123...

Total reclaimed space: 456MB

Common Flags:

FlagPurpose
-aRemove all unused images, not just dangling
-fForce, no confirmation prompt
--volumesPrune volumes as well

Force prune (no prompt):

bash
$ docker system prune -f

Prune everything (images, containers, volumes):

bash
$ docker system prune -a -f --volumes

Quick Reference — Most Used Commands

TaskCommand
Show versiondocker version
Show system infodocker info
Show general helpdocker --help
Show command helpdocker run --help
Show disk usagedocker system df
Show detailed disk usagedocker system df -v
Prune unused datadocker system prune
Prune all (force)docker system prune -a -f --volumes

Pro Tips

  1. Verify Docker is running:

    bash
    docker version
    # If you see "Cannot connect to the Docker daemon", Docker isn't running
  2. Start Docker on Linux:

    bash
    sudo systemctl start docker
    sudo systemctl enable docker
  3. Check Docker logs (Linux):

    bash
    sudo journalctl -u docker -f
  4. Docker runs as root by default — add your user to the docker group:

    bash
    sudo usermod -aG docker $USER
  5. Clean up regularly — docker system prune to free disk space.

  6. Check Docker disk usage — docker system df before and after pruning.

  7. Enable CLI autocomplete:

    bash
    source /usr/share/bash-completion/completions/docker

Next in DockerWorking with Images
Docker cheat sheet: Docker Basics & Installation | InfraThrone DevOps Park