Docker_installation
Chapter 02: Docker Installation
Section titled “Chapter 02: Docker Installation”This chapter covers installing Docker on various operating systems. Docker can be installed on Linux, macOS, and Windows.
System Requirements
Section titled “System Requirements”- 64-bit Linux kernel 3.10 or later
- Ubuntu, Debian, CentOS, Fedora, or RHEL
- Root or sudo access
- 2010 or newer Mac
- macOS 10.15 (Catalina) or later
- At least 4GB RAM
Windows
Section titled “Windows”- Windows 10/11 Pro, Enterprise, or Education
- Hyper-V and Containers features enabled
- At least 4GB RAM
Installing Docker on Ubuntu/Debian
Section titled “Installing Docker on Ubuntu/Debian”Method 1: Using apt (Recommended)
Section titled “Method 1: Using apt (Recommended)”# Update package indexsudo apt-get update
# Install dependenciessudo apt-get install -y \ ca-certificates \ curl \ gnupg \ lsb-release
# Add Docker's official GPG keysudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Set up the Docker repositoryecho \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index againsudo apt-get update
# Install Docker Enginesudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Verify installationsudo docker run hello-worldMethod 2: Using convenience script
Section titled “Method 2: Using convenience script”# Download and run the convenience scriptcurl -fsSL https://get.docker.com -o get-docker.shsudo sh get-docker.sh
# Add user to docker group (avoid using sudo)sudo usermod -aG docker $USER
# Log out and log back in for group membership to take effectPost-Installation Steps
Section titled “Post-Installation Steps”# Start Docker servicesudo systemctl start dockersudo systemctl enable docker
# Check Docker versiondocker --version
# Check Docker Compose versiondocker compose version
# View Docker system informationdocker system infoInstalling Docker on CentOS/RHEL/Fedora
Section titled “Installing Docker on CentOS/RHEL/Fedora”CentOS/RHEL 8/9 or Fedora
Section titled “CentOS/RHEL 8/9 or Fedora”# Install required packagessudo dnf install -y dnf-plugins-core
# Set up the Docker repositorysudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# Install Docker Enginesudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Start and enable Dockersudo systemctl start dockersudo systemctl enable docker
# Verify installationsudo docker run hello-worldInstalling Docker on macOS
Section titled “Installing Docker on macOS”Option 1: Using Homebrew (Recommended)
Section titled “Option 1: Using Homebrew (Recommended)”# Install Homebrew if not already installed/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Docker Desktopbrew install --cask docker
# Launch Docker Desktop from Applicationsopen -a DockerOption 2: Manual Download
Section titled “Option 2: Manual Download”- Go to Docker Desktop for Mac
- Download the Apple Silicon or Intel version
- Double-click the
.dmgfile - Drag Docker to Applications folder
- Launch Docker Desktop
Verify Installation
Section titled “Verify Installation”# Check Docker versiondocker --version
# Check Docker Compose versiondocker compose version
# Run a test containerdocker run hello-worldDocker Desktop for Mac Architecture
Section titled “Docker Desktop for Mac Architecture”┌─────────────────────────────────────────────────────────────────────────────┐│ Docker Desktop for Mac Architecture │├─────────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Docker Desktop App │ ││ │ │ ││ │ ┌────────────────┐ ┌────────────────┐ ┌─────────────┐ │ ││ │ │ Docker CLI │ │ Docker API │ │ UI/Config │ │ ││ │ └────────────────┘ └────────────────┘ └─────────────┘ │ ││ └────────────────────────────┬────────────────────────────────────┘ ││ │ ││ ▼ ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Linux VM (HyperKit) │ ││ │ │ ││ │ ┌────────────────┐ ┌────────────────┐ │ ││ │ │ Docker Daemon │ │ Containerd │ │ ││ │ │ (dockerd) │ │ │ │ ││ │ └────────────────┘ └────────────────┘ │ ││ └────────────────────────────┬────────────────────────────────────┘ ││ │ ││ ┌────────────────────────────▼────────────────────────────────────┐ ││ │ macOS Kernel │ ││ └─────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────────┘Installing Docker on Windows
Section titled “Installing Docker on Windows”Prerequisites
Section titled “Prerequisites”-
Enable Hyper-V:
- Open PowerShell as Administrator
- Run:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
-
Enable Containers:
- Run:
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
- Run:
-
Restart computer
Installation Steps
Section titled “Installation Steps”-
Download Docker Desktop for Windows from docker.com
-
Run the installer (
Docker Desktop Installer.exe) -
Follow the installation wizard:
- Accept the license
- Choose “Use WSL 2 instead of Hyper-V” (recommended)
- Complete installation
-
Start Docker Desktop
-
Verify with:
docker --versiondocker run hello-worldDocker Desktop for Windows Architecture
Section titled “Docker Desktop for Windows Architecture”┌─────────────────────────────────────────────────────────────────────────────┐│ Docker Desktop for Windows Architecture │├─────────────────────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Docker Desktop App │ ││ │ │ ││ │ ┌────────────────┐ ┌────────────────┐ ┌─────────────┐ │ ││ │ │ Docker CLI │ │ Docker API │ │ UI/GUI │ │ ││ │ └────────────────┘ └────────────────┘ └─────────────┘ │ ││ └────────────────────────────┬────────────────────────────────────┘ ││ │ ││ ┌────────────────────────────▼────────────────────────────────────┐ ││ │ WSL 2 Backend │ ││ │ │ ││ │ ┌────────────────┐ ┌────────────────┐ │ ││ │ │ Docker Engine │ │ containerd │ │ ││ │ │ (dockerd) │ │ │ │ ││ │ └────────────────┘ └────────────────┘ │ ││ └────────────────────────────┬────────────────────────────────────┘ ││ │ ││ ┌────────────────────────────▼────────────────────────────────────┐ ││ │ Linux Kernel (WSL2) │ ││ └─────────────────────────────────────────────────────────────────┘ ││ ││ ┌─────────────────────────────────────────────────────────────────┐ ││ │ Windows Kernel │ ││ └─────────────────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────────────────────┘Docker Desktop vs Docker Engine
Section titled “Docker Desktop vs Docker Engine”Docker Desktop
Section titled “Docker Desktop”- Complete Docker development environment
- Includes Docker Engine, CLI, Docker Compose, Kubernetes
- GUI for management
- Paid for large enterprises
- Easy to install and use
Docker Engine (Standalone)
Section titled “Docker Engine (Standalone)”- Just the core Docker components
- CLI and daemon only
- Free and open-source
- Requires manual configuration
- Used in production Linux servers
Installing Docker Compose
Section titled “Installing Docker Compose”Docker Compose is included in Docker Desktop installations. For Linux servers:
Method 1: Using apt/dnf
Section titled “Method 1: Using apt/dnf”# Ubuntu/Debiansudo apt-get install docker-compose-plugin
# CentOS/RHEL/Fedorasudo dnf install docker-compose-pluginMethod 2: Manual installation
Section titled “Method 2: Manual installation”# Download the current stable releasesudo curl -L "https://github.com/docker/compose/releases/download/v2.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# Apply executable permissionssudo chmod +x /usr/local/bin/docker-compose
# Verify installationdocker-compose --versionUninstalling Docker
Section titled “Uninstalling Docker”Ubuntu/Debian
Section titled “Ubuntu/Debian”# Remove Docker packagessudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Remove images, containers, volumessudo rm -rf /var/lib/dockersudo rm -rf /var/lib/containerd# Using Homebrewbrew uninstall --cask docker
# Or remove manuallyrm -rf ~/Library/Application\ Support/Dockerrm -rf ~/Library/Group\ Containers/group.com.dockerWindows
Section titled “Windows”- Open Docker Desktop
- Go to Settings → Troubleshoot → Uninstall
Verifying Docker Installation
Section titled “Verifying Docker Installation”Run Hello World
Section titled “Run Hello World”$ docker run hello-world
Unable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world2db29710123e: Pull completeDigest: sha256:6Status: Downloaded newer image for hello-world:latest
Hello from Docker!This message shows that your installation appears to be working correctly.Check Docker Info
Section titled “Check Docker Info”$ docker info
Client: Context: default Debug Mode: false Plugins: build: Buildx compose: Docker Compose
Server: Containers: 2 Images: 15 Server Version: 24.0.0 Storage Driver: overlay2Common Installation Issues
Section titled “Common Installation Issues”1. Permission Denied
Section titled “1. Permission Denied”# Add user to docker groupsudo usermod -aG docker $USER
# Or use sudo for each command2. Docker daemon not running
Section titled “2. Docker daemon not running”# Start Docker servicesudo systemctl start dockersudo systemctl enable docker3. WSL2 installation incomplete
Section titled “3. WSL2 installation incomplete”# Update WSL2wsl --update
# List installed distributionswsl --list --verboseNext Steps
Section titled “Next Steps”Now that Docker is installed, let’s learn about Docker Images in the next chapter.