Learn how to install Docker on any platform and understand its internal architecture. Master the Docker daemon, CLI, and registry components that make containerization work.
Before you can containerize applications, you need Docker installed and running. But Docker is more than just a single program—it's a sophisticated platform with multiple components working together to build, ship, and run containers efficiently.
Understanding Docker's architecture isn't just academic knowledge. When things go wrong (and they will), knowing how Docker works internally helps you troubleshoot effectively. When you're optimizing builds or debugging network issues, architectural knowledge is invaluable.
In this hands-on lesson, you'll install Docker on your system, explore its internal architecture, and run your first containers. By the end, you'll have a fully functional Docker environment and a solid understanding of how all the pieces fit together.
Docker uses a client-server architecture. Understanding each component helps you work effectively with Docker and troubleshoot issues.
The Three Main Components:
1. Docker Client (docker CLI)
The command-line interface you interact with:
docker run, docker build, docker pull2. Docker Daemon (dockerd)
The background service that does the heavy lifting:
3. Docker Registry
Stores and distributes Docker images:
Architecture Diagram:
1┌─────────────────────────────────────────────────────────────┐
2│ YOUR MACHINE │
3│ │
4│ ┌──────────────┐ ┌────────────────────────────┐ │
5│ │ │ REST │ Docker Daemon │ │
6│ │ Docker CLI │ API │ (dockerd) │ │
7│ │ (docker) │ ──────► │ │ │
8│ │ │ │ ┌──────┐ ┌──────┐ ┌────┐ │ │
9│ └──────────────┘ │ │Images│ │Cont- │ │Net-│ │ │
10│ │ │ │ │ainers│ │work│ │ │
11│ │ └──────┘ └──────┘ └────┘ │ │
12│ │ │ │
13│ └─────────────┬──────────────┘ │
14│ │ │
15└──────────────────────────────────────────┼───────────────────┘
16 │
17 │ Pull/Push
18 ▼
19 ┌────────────────────────┐
20 │ Docker Registry │
21 │ (Docker Hub, ECR, │
22 │ GCR, private) │
23 └────────────────────────┘Communication Flow:
docker run nginxnginx image available?Key Insight:
The Docker CLI and daemon don't have to be on the same machine. You can control a remote Docker daemon using the DOCKER_HOST environment variable—useful for managing servers or working with Docker Machine.
Linux is Docker's native environment. Here's how to install Docker Engine on Ubuntu/Debian and RHEL/CentOS systems.
Ubuntu/Debian Installation:
1# 1. Update package index
2sudo apt-get update
3
4# 2. Install prerequisites
5sudo apt-get install -y \
6 ca-certificates \
7 curl \
8 gnupg \
9 lsb-release
10
11# 3. Add Docker's official GPG key
12sudo mkdir -p /etc/apt/keyrings
13curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
14
15# 4. Set up the repository
16echo \
17 "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
18 $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
19
20# 5. Install Docker Engine
21sudo apt-get update
22sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
23
24# 6. Verify installation
25sudo docker run hello-worldRHEL/CentOS Installation:
1# 1. Remove old versions
2sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
3
4# 2. Install prerequisites
5sudo yum install -y yum-utils
6
7# 3. Add Docker repository
8sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
9
10# 4. Install Docker Engine
11sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
12
13# 5. Start Docker
14sudo systemctl start docker
15sudo systemctl enable docker
16
17# 6. Verify installation
18sudo docker run hello-worldPost-Installation Steps (All Linux):
1# Run Docker without sudo (recommended for development)
2sudo groupadd docker
3sudo usermod -aG docker $USER
4newgrp docker
5
6# Verify non-root access
7docker run hello-world
8
9# Configure Docker to start on boot
10sudo systemctl enable docker.service
11sudo systemctl enable containerd.serviceImportant Security Note:
Adding your user to the docker group grants root-equivalent privileges. Only do this on development machines, not production servers.
Docker Desktop provides a complete Docker environment for Windows and macOS, including GUI tools and Kubernetes.
Windows Installation:
System Requirements:
Installation Steps:
1# Open PowerShell as Administrator
2wsl --install
3# Restart your computer
4# After restart, set WSL 2 as default
5wsl --set-default-version 21docker --version
2docker run hello-worldmacOS Installation:
System Requirements:
Installation Steps:
1docker --version
2docker run hello-worldDocker Desktop Features:
Performance Tips:
The Docker daemon can be customized through configuration files and command-line options.
Configuration File Location:
/etc/docker/daemon.jsonC:\ProgramData\docker\config\daemon.jsonCommon Configuration Options:
1{
2 "data-root": "/var/lib/docker",
3 "storage-driver": "overlay2",
4 "log-driver": "json-file",
5 "log-opts": {
6 "max-size": "10m",
7 "max-file": "3"
8 },
9 "default-address-pools": [
10 {
11 "base": "172.17.0.0/16",
12 "size": 24
13 }
14 ],
15 "dns": ["8.8.8.8", "8.8.4.4"],
16 "insecure-registries": [],
17 "registry-mirrors": ["https://mirror.gcr.io"],
18 "live-restore": true,
19 "debug": false,
20 "tls": true,
21 "tlscacert": "/etc/docker/ca.pem",
22 "tlscert": "/etc/docker/server-cert.pem",
23 "tlskey": "/etc/docker/server-key.pem"
24}Key Configuration Options Explained:
Storage Configuration:
1{
2 "data-root": "/mnt/docker-data",
3 "storage-driver": "overlay2"
4}data-root: Where Docker stores images, containers, volumesstorage-driver: overlay2 is recommended for most Linux systemsLogging Configuration:
1{
2 "log-driver": "json-file",
3 "log-opts": {
4 "max-size": "10m",
5 "max-file": "3"
6 }
7}Network Configuration:
1{
2 "dns": ["8.8.8.8", "1.1.1.1"],
3 "bip": "172.26.0.1/16",
4 "fixed-cidr": "172.26.0.0/24"
5}Registry Configuration:
1{
2 "insecure-registries": ["myregistry.local:5000"],
3 "registry-mirrors": ["https://mirror.gcr.io"]
4}Applying Configuration Changes:
1# Edit configuration
2sudo nano /etc/docker/daemon.json
3
4# Restart Docker daemon
5sudo systemctl restart docker
6
7# Verify configuration
8docker infoTroubleshooting Daemon Issues:
1# Check daemon status
2sudo systemctl status docker
3
4# View daemon logs
5sudo journalctl -u docker.service
6
7# Check for configuration errors
8sudo dockerd --validate
9
10# Run daemon in debug mode (temporary)
11sudo dockerd --debugAfter installation, it's important to verify Docker is working correctly and understand the diagnostic commands.
Basic Verification:
1# Check Docker version
2docker --version
3# Output: Docker version 24.0.7, build afdd53b
4
5# Check detailed version info
6docker version
7# Shows client and server versions
8
9# Run test container
10docker run hello-world
11# Downloads and runs the hello-world imageSystem Information:
1# Comprehensive system info
2docker infoThis shows:
Example Output:
1Client: Docker Engine - Community
2 Version: 24.0.7
3 Context: default
4
5Server:
6 Containers: 5
7 Running: 2
8 Paused: 0
9 Stopped: 3
10 Images: 23
11 Server Version: 24.0.7
12 Storage Driver: overlay2
13 Logging Driver: json-file
14 Cgroup Driver: systemd
15 Kernel Version: 5.15.0-91-generic
16 Operating System: Ubuntu 22.04.3 LTS
17 OSType: linux
18 Architecture: x86_64
19 CPUs: 8
20 Total Memory: 15.61GiBTest Docker Functionality:
1# Test running containers
2docker run -d --name test-nginx -p 8080:80 nginx
3curl http://localhost:8080
4
5# Test volume mounting
6docker run -v $(pwd):/data alpine ls /data
7
8# Test networking
9docker network ls
10docker network create test-network
11docker network rm test-network
12
13# Test building images
14echo 'FROM alpine' > Dockerfile
15docker build -t test-image .
16docker rmi test-image
17
18# Clean up test container
19docker stop test-nginx
20docker rm test-nginxCommon Installation Issues:
Issue: Permission denied
1# Solution: Add user to docker group
2sudo usermod -aG docker $USER
3# Log out and back inIssue: Cannot connect to Docker daemon
1# Solution: Start the daemon
2sudo systemctl start docker
3# Or check if Docker Desktop is runningIssue: DNS resolution fails in containers
1# Solution: Configure DNS in daemon.json
2{"dns": ["8.8.8.8", "8.8.4.4"]}Issue: Slow performance on Windows/Mac
1# Solution:
2# - Use WSL 2 backend on Windows
3# - Increase allocated memory
4# - Use volume mounts sparingly for node_modulesA comprehensive script that verifies your Docker installation, displays system information, and tests core functionality.
1#!/bin/bash
2# =============================================================================
3# Docker Installation Verification Script
4# =============================================================================
5# This script verifies your Docker installation and tests core functionality
6# Run: chmod +x verify-docker.sh && ./verify-docker.sh
7
8set -e # Exit on first error
9
10# Colors for output
11RED='\033[0;31m'
12GREEN='\033[0;32m'
13YELLOW='\033[1;33m'
14BLUE='\033[0;34m'
15NC='\033[0m' # No Color
16
17# Header
18echo -e "${BLUE}"
19echo "=============================================="
20echo " Docker Installation Verification"
21echo "=============================================="
22echo -e "${NC}"
23
24# =============================================================================
25# 1. Check Docker CLI
26# =============================================================================
27echo -e "${YELLOW}[1/7] Checking Docker CLI...${NC}"
28
29if command -v docker &> /dev/null; then
30 DOCKER_VERSION=$(docker --version)
31 echo -e "${GREEN}✓ Docker CLI installed: ${DOCKER_VERSION}${NC}"
32else
33 echo -e "${RED}✗ Docker CLI not found. Please install Docker.${NC}"
34 exit 1
35fi
36
37# =============================================================================
38# 2. Check Docker Daemon
39# =============================================================================
40echo -e "${YELLOW}[2/7] Checking Docker daemon...${NC}"
41
42if docker info &> /dev/null; then
43 echo -e "${GREEN}✓ Docker daemon is running${NC}"
44else
45 echo -e "${RED}✗ Docker daemon is not running${NC}"
46 echo " Try: sudo systemctl start docker"
47 exit 1
48fi
49
50# =============================================================================
51# 3. Display System Information
52# =============================================================================
53echo -e "${YELLOW}[3/7] System Information:${NC}"
54
55echo ""
56echo "Docker Version:"
57docker version --format ' Client: {{.Client.Version}} ({{.Client.Os}}/{{.Client.Arch}})
58 Server: {{.Server.Version}} ({{.Server.Os}}/{{.Server.Arch}})'
59
60echo ""
61echo "System Details:"
62docker info --format ' Containers: {{.Containers}} ({{.ContainersRunning}} running)
63 Images: {{.Images}}
64 Storage Driver: {{.Driver}}
65 Cgroup Driver: {{.CgroupDriver}}
66 Kernel: {{.KernelVersion}}
67 OS: {{.OperatingSystem}}
68 CPUs: {{.NCPU}}
69 Memory: {{.MemTotal}}'
70
71# =============================================================================
72# 4. Test Image Pull
73# =============================================================================
74echo ""
75echo -e "${YELLOW}[4/7] Testing image pull (alpine:latest)...${NC}"
76
77if docker pull alpine:latest &> /dev/null; then
78 echo -e "${GREEN}✓ Successfully pulled alpine:latest${NC}"
79else
80 echo -e "${RED}✗ Failed to pull image${NC}"
81 echo " Check your internet connection and registry access"
82fi
83
84# =============================================================================
85# 5. Test Container Run
86# =============================================================================
87echo -e "${YELLOW}[5/7] Testing container execution...${NC}"
88
89CONTAINER_OUTPUT=$(docker run --rm alpine echo "Hello from Docker!")
90if [ "$CONTAINER_OUTPUT" == "Hello from Docker!" ]; then
91 echo -e "${GREEN}✓ Container execution works: ${CONTAINER_OUTPUT}${NC}"
92else
93 echo -e "${RED}✗ Container execution failed${NC}"
94fi
95
96# =============================================================================
97# 6. Test Volume Mount
98# =============================================================================
99echo -e "${YELLOW}[6/7] Testing volume mount...${NC}"
100
101# Create test file
102TEST_DIR=$(mktemp -d)
103echo "test content" > "$TEST_DIR/test.txt"
104
105# Test volume mount
106MOUNT_OUTPUT=$(docker run --rm -v "$TEST_DIR:/data" alpine cat /data/test.txt 2>&1)
107if [ "$MOUNT_OUTPUT" == "test content" ]; then
108 echo -e "${GREEN}✓ Volume mounting works${NC}"
109else
110 echo -e "${RED}✗ Volume mounting failed${NC}"
111fi
112
113# Cleanup
114rm -rf "$TEST_DIR"
115
116# =============================================================================
117# 7. Test Networking
118# =============================================================================
119echo -e "${YELLOW}[7/7] Testing Docker networking...${NC}"
120
121# Test DNS resolution
122DNS_TEST=$(docker run --rm alpine nslookup google.com 2>&1 | grep -c "Address" || true)
123if [ "$DNS_TEST" -gt 0 ]; then
124 echo -e "${GREEN}✓ Container DNS resolution works${NC}"
125else
126 echo -e "${YELLOW}⚠ DNS resolution may have issues${NC}"
127fi
128
129# Test network creation
130TEST_NETWORK="test-network-$$"
131if docker network create "$TEST_NETWORK" &> /dev/null; then
132 echo -e "${GREEN}✓ Network creation works${NC}"
133 docker network rm "$TEST_NETWORK" &> /dev/null
134else
135 echo -e "${RED}✗ Network creation failed${NC}"
136fi
137
138# =============================================================================
139# Summary
140# =============================================================================
141echo ""
142echo -e "${BLUE}"
143echo "=============================================="
144echo " Verification Complete"
145echo "=============================================="
146echo -e "${NC}"
147
148echo ""
149echo "Your Docker installation is ready! Next steps:"
150echo ""
151echo " 1. Run your first container:"
152echo " docker run -d -p 8080:80 nginx"
153echo ""
154echo " 2. View running containers:"
155echo " docker ps"
156echo ""
157echo " 3. Build your first image:"
158echo " echo 'FROM alpine' > Dockerfile"
159echo " docker build -t my-image ."
160echo ""
161echo " 4. Explore Docker Hub:"
162echo " https://hub.docker.com/"
163echo ""
164
165# Additional info for development
166echo -e "${YELLOW}Development Tips:${NC}"
167echo " • Add yourself to docker group to avoid sudo:"
168echo " sudo usermod -aG docker $USER"
169echo ""
170echo " • Configure log rotation in /etc/docker/daemon.json:"
171echo ' {"log-opts": {"max-size": "10m", "max-file": "3"}}'
172echo ""
173echo " • For Windows/Mac: Use Docker Desktop settings"
174echo " to allocate sufficient CPU and memory"
175echo ""This verification script provides a comprehensive check of your Docker installation:
🔍 What It Checks:
1. Docker CLI Availability
docker command is in PATH2. Docker Daemon Status
docker info as a connectivity test3. System Information
4. Image Pull Test
5. Container Execution Test
6. Volume Mount Test
7. Networking Test
Color-Coded Output:
Why This Matters:
Running this script after installation ensures all Docker components work correctly before you start containerizing applications. It catches common issues like permission problems, daemon configuration errors, or networking misconfigurations.
Excellent work setting up Docker! You now have a working Docker environment and understand how Docker's components work together.
In our next lesson, "Docker Images & Containers," you'll dive deep into the core concepts of images and containers. You'll learn how to find images on Docker Hub, run containers with various options, and manage the container lifecycle.
Get ready to start running real containers!
Your progress is saved in this browser, on this device only.