Chapter 02 • Core Foundations

Docker Installation & Setup Guide

Installing Docker correctly requires understanding how your operating system interacts with the Linux kernel. On native Linux, Docker runs bare-metal without virtualization overhead. On Windows and macOS, Docker operates via lightweight, hardware-accelerated Linux micro-virtual machines (WSL2 on Windows, Apple Virtualization Framework on Mac).

1. Production Installation on Ubuntu / Debian Linux

Do not use apt install docker.io from standard Ubuntu mirrors, as those packages are often outdated. Always install the official Docker Community Edition (docker-ce) repository:

# Step 1: Remove old legacy packages if present
sudo apt-get remove -y docker docker-engine docker.io containerd runc

# Step 2: Install security certificates and curl
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release

# Step 3: Add Docker's official GPG encryption key to modern apt keyrings
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Step 4: Add the stable apt repository to package sources
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Step 5: Update indices and install Docker Engine, CLI, Containerd, and Compose V2
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Step 6: Verify and enable systemd daemon service
sudo systemctl enable --now docker

Mandatory Linux Post-Install: Non-Root User Access

By default, the Docker daemon binds to a UNIX socket owned by user root and group docker. To run docker commands without prepending sudo, add your current user to the docker security group:

# 1. Create docker group if not already present
sudo groupadd docker

# 2. Add your current user to the docker group
sudo usermod -aG docker $USER

# 3. Activate the new group membership immediately (or log out and log back in)
newgrp docker

# 4. Verify that sudo is no longer needed
docker ps

2. Windows 10 / 11 Installation (WSL2 Backend)

Modern Windows installations utilize Windows Subsystem for Linux 2 (WSL2) rather than the legacy Hyper-V virtual machine backend. WSL2 uses a real Linux kernel maintained by Microsoft, providing dynamic RAM allocation, instant startup, and native file sharing.

Step-by-Step Windows Setup:
  1. Open PowerShell as Administrator and ensure WSL is installed and updated:
    wsl --install --no-distribution wsl --update wsl --set-default-version 2
  2. Install Ubuntu from the Microsoft Store or via CLI: wsl --install -d Ubuntu.
  3. Download the Docker Desktop Windows Installer from the official Docker portal.
  4. During installation, make sure the checkbox "Use WSL 2 instead of Hyper-V (recommended)" is selected.
  5. In Docker Desktop Settings → Resources → WSL Integration, enable integration with your default Ubuntu distribution.
Pro Tip: Prevent Windows RAM Exhaustion! By default, WSL2 can consume up to 50% of your machine's total physical RAM. Create a file at C:\Users\<YourUsername>\.wslconfig with the following content to cap memory consumption:
[wsl2]
memory=6GB
processors=4
swap=2GB

3. macOS Installation (Apple Silicon & Intel)

On macOS, Docker Desktop utilizes the lightweight Apple Virtualization Framework andVirtioFS to deliver accelerated file system throughput between the Mac APFS filesystem and the Linux VM:

# Option A: Install via Homebrew Cask
brew install --cask docker

# Option B: Manual .dmg download
# Download Docker.dmg (Choose Apple Silicon ARM64 for M1/M2/M3 or Intel x86_64)
Running Legacy x86_64 Images on Apple Silicon

Apple Silicon chips (ARM64 architecture) can execute legacy Intel/AMD x86_64 container images via Rosetta 2 emulation. Simply pass the target platform flag when running or building:docker run --platform linux/amd64 -d nginx.

4. Verifying System Installation

Verify that your Docker client can communicate with the daemon and successfully pull and execute container images:

# 1. Print client and server versions
docker version

# 2. Inspect comprehensive daemon architecture & driver details
docker info

# 3. Execute the diagnostic hello-world container
docker run hello-world

When docker run hello-world executes, Docker performs the following four automated actions:

  1. Checks local image cache for hello-world:latest.
  2. Detects a cache miss and pulls the layers from Docker Hub over TLS.
  3. Creates an isolated container instance with dedicated namespaces and cgroups.
  4. Executes the binary, streams the output text to your terminal, and exits cleanly.

Next Up: Docker Architecture & Daemon Internals

In Chapter 3, explore how the Docker CLI, dockerd REST API daemon, containerd, and runc work together under the hood.

Chapter 03: Docker Architecture & Concepts →

Explore Related Tools

Hand-picked utilities and calculators related to this tool.

Related Tools