Skip to main content

Docker Installation Guide

Docker is a platform for developing, shipping, and running applications in containers. This guide will help you install Docker on your system.

Prerequisites

Before installing Docker, ensure your system meets the following requirements:

  • Linux: Kernel version 3.10 or higher
  • Windows: Windows 10/11 Pro, Enterprise, or Education (64-bit)
  • macOS: macOS 10.15 or newer
  • RAM: At least 4GB (8GB recommended)
  • Storage: At least 20GB free space

Installing Docker on Linux

Ubuntu/Debian

# Update package index
sudo apt-get update

# Install prerequisites
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Set up the repository
echo \
"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

# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Add your user to the docker group (optional)
sudo usermod -aG docker $USER

CentOS/RHEL/Fedora

# Install prerequisites
sudo yum install -y yum-utils

# Add Docker repository
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Add your user to the docker group (optional)
sudo usermod -aG docker $USER

Installing Docker on Windows

  1. Download Docker Desktop:

  2. Install Docker Desktop:

    # Run the installer as Administrator
    Start-Process -FilePath "Docker Desktop Installer.exe" -Verb RunAs
  3. Enable WSL 2 (if not already enabled):

    # Enable WSL feature
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

    # Enable Virtual Machine feature
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

    # Restart your computer
    Restart-Computer
  4. Install WSL 2 Linux kernel:

    # Download and install WSL 2 kernel
    Invoke-WebRequest -Uri "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -OutFile "wsl_update_x64.msi"
    Start-Process -FilePath "wsl_update_x64.msi" -ArgumentList "/quiet" -Wait
  5. Set WSL 2 as default:

    wsl --set-default-version 2

Using WSL 2 Backend

# Install Docker in WSL 2
wsl --install -d Ubuntu

# In WSL 2 Ubuntu, run the Linux installation commands
sudo apt-get update
sudo apt-get install docker.io
sudo systemctl start docker
sudo systemctl enable docker

Installing Docker on macOS

  1. Download Docker Desktop:

  2. Install Docker Desktop:

    # Mount the downloaded .dmg file
    hdiutil attach Docker.dmg

    # Copy Docker to Applications
    cp -R /Volumes/Docker/Docker.app /Applications/

    # Unmount the disk image
    hdiutil detach /Volumes/Docker
  3. Start Docker Desktop:

    • Open Docker Desktop from Applications
    • Follow the setup wizard

Using Homebrew

# Install Docker using Homebrew
brew install --cask docker

# Start Docker Desktop
open /Applications/Docker.app

Using Colima (Alternative to Docker Desktop)

Colima is a lightweight Docker Desktop alternative for macOS that provides Docker Engine and Docker Compose without the overhead of Docker Desktop.

Prerequisites

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Docker CLI
brew install docker

# Install Docker Compose
brew install docker-compose

Install Colima

# Install Colima using Homebrew
brew install colima

# Start Colima with default settings
colima start

# Verify installation
docker --version
docker-compose --version

Advanced Colima Configuration

# Start Colima with custom settings
colima start \
--cpu 4 \
--memory 8 \
--disk 100 \
--arch x86_64

# Start with specific Docker version
colima start --kubernetes --kubernetes-version v1.24.0

# Start with custom Docker daemon configuration
colima start --edit

# Stop Colima
colima stop

# Delete Colima VM
colima delete

# Show Colima status
colima status

Colima with Different Architectures

# For Apple Silicon (M1/M2) Macs
colima start --arch aarch64

# For Intel Macs
colima start --arch x86_64

# Start with Rosetta 2 for x86_64 compatibility
colima start --arch x86_64 --vm-type=qemu

Colima with Kubernetes

# Start Colima with Kubernetes
colima start --kubernetes

# Start with specific Kubernetes version
colima start --kubernetes --kubernetes-version v1.24.0

# Enable Kubernetes dashboard
colima start --kubernetes --kubernetes-dashboard

# Check Kubernetes status
kubectl cluster-info

Colima Configuration File

Create ~/.colima/default/colima.yaml for persistent configuration:

# Colima configuration
cpu: 4
memory: 8
disk: 100
arch: x86_64
kubernetes:
enabled: false
version: v1.24.0
docker:
daemon:
features:
buildkit: true
experimental: true

Troubleshooting Colima

# Check Colima logs
colima logs

# Restart Colima
colima stop
colima start

# Reset Colima completely
colima delete
colima start

# Check Docker daemon
docker system info

# Test Docker functionality
docker run hello-world

Colima vs Docker Desktop

FeatureColimaDocker Desktop
Resource UsageLightweightHeavy
Startup TimeFastSlow
KubernetesOptionalBuilt-in
GUICLI onlyFull GUI
UpdatesManualAutomatic
CostFreeFree/Paid
CustomizationHighLimited

Colima Best Practices

  1. Resource Allocation:

    # Allocate appropriate resources
    colima start --cpu 4 --memory 8 --disk 100
  2. Architecture Selection:

    # Use native architecture for better performance
    colima start --arch aarch64 # For Apple Silicon
    colima start --arch x86_64 # For Intel
  3. Docker Compose Integration:

    # Colima works seamlessly with Docker Compose
    docker-compose up -d
  4. Development Workflow:

    # Start Colima for development
    colima start --cpu 2 --memory 4

    # Use Docker normally
    docker build -t myapp .
    docker run myapp

    # Stop when done
    colima stop

Verifying Installation

After installation, verify Docker is working correctly:

# Check Docker version
docker --version

# Run hello-world container
docker run hello-world

# Check Docker system info
docker system info

Docker Compose Installation

Docker Compose is included with Docker Desktop. For Linux installations:

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# Make it executable
sudo chmod +x /usr/local/bin/docker-compose

# Verify installation
docker-compose --version

Post-Installation Steps

Configure Docker Daemon (Optional)

Create or edit /etc/docker/daemon.json:

{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"storage-driver": "overlay2",
"insecure-registries": [],
"registry-mirrors": []
}

Restart Docker

# Linux
sudo systemctl restart docker

# macOS/Windows
# Restart Docker Desktop from the application

Troubleshooting

Common Issues

  1. Permission Denied:

    # Add user to docker group
    sudo usermod -aG docker $USER
    newgrp docker
  2. Docker Daemon Not Running:

    # Start Docker service
    sudo systemctl start docker
  3. WSL 2 Issues on Windows:

    # Update WSL
    wsl --update

    # Restart WSL
    wsl --shutdown

Getting Help

Next Steps

Now that Docker is installed, you can:

  1. Learn Docker basics
  2. Create your first container
  3. Build Docker images
  4. Work with Docker Compose

Congratulations! You've successfully installed Docker on your system.