Skip to content

Installation Guide

This guide covers installing Docker on all major platforms: Windows, macOS, and Linux. Docker Desktop is the recommended installation for development environments, while Docker Engine is recommended for production Linux servers.

System Requirements

Minimum Requirements

PlatformProcessorRAMDisk SpaceOS Version
Windows64-bit with SLAT4 GB20 GBWindows 10/11 (21H2+)
macOSApple Silicon or Intel4 GB20 GBmacOS 12.0+ (Monterey)
Linux64-bit (x86_64/amd64, arm64)2 GB15 GBKernel 3.10+

Windows Installation

Docker Desktop for Windows

Docker Desktop for Windows uses WSL 2 (Windows Subsystem for Linux) as the backend for running containers.

Prerequisites

  1. Enable WSL 2:
powershell
# Open PowerShell as Administrator
wsl --install

# Verify WSL version
wsl --list --verbose
  1. Enable Virtualization in BIOS/UEFI (Intel VT-x or AMD-V).

  2. Enable Hyper-V (optional, WSL 2 is preferred):

powershell
# Enable Hyper-V via PowerShell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

Installation Steps

  1. Download Docker Desktop for Windows from the official Docker website.

  2. Run the installer (Docker Desktop Installer.exe).

  3. During installation, ensure "Use WSL 2 instead of Hyper-V" is selected.

  4. Follow the installation wizard to completion.

  5. Restart your computer when prompted.

  6. Launch Docker Desktop from the Start menu.

Post-Installation Verification

powershell
# Verify Docker is installed correctly
docker --version
# Example output: Docker version 27.x.x, build xxxxxxx

# Verify Docker Compose
docker compose version
# Example output: Docker Compose version v2.x.x

# Run the hello-world container
docker run hello-world

Windows Configuration

powershell
# Configure Docker to start on boot (via Docker Desktop settings)
# Settings > General > Start Docker Desktop when you sign in

# Configure WSL 2 resource limits
# Create or edit: %USERPROFILE%\.wslconfig

Example .wslconfig file:

ini
[wsl2]
memory=8GB
processors=4
swap=2GB
localhostForwarding=true

macOS Installation

Docker Desktop for macOS

Docker Desktop for macOS supports both Apple Silicon (M1/M2/M3) and Intel processors.

Installation Steps

Option 1: Download from Website

  1. Download Docker Desktop for Mac from the official Docker website.
  2. Select the correct version for your chip: Apple Silicon or Intel.
  3. Open the downloaded .dmg file.
  4. Drag the Docker icon to the Applications folder.
  5. Launch Docker from the Applications folder.
  6. Accept the license agreement and complete the setup.

Option 2: Install via Homebrew

bash
# Install Docker Desktop using Homebrew
brew install --cask docker

# Launch Docker Desktop
open /Applications/Docker.app

Post-Installation Verification

bash
# Verify Docker is installed
docker --version

# Verify Docker Compose
docker compose version

# Run the hello-world container
docker run hello-world

# Check Docker system information
docker info

macOS Resource Configuration

Configure resource limits through Docker Desktop:

  • SettingsResourcesAdvanced
SettingRecommendedDescription
CPUs4+Number of CPU cores allocated
Memory8 GB+RAM allocated to Docker
Swap2 GBSwap memory size
Disk image size60 GB+Maximum disk space for images and containers

Linux Installation

Docker Engine for Linux

Docker Engine is installed directly on Linux distributions. The following instructions cover the most popular distributions.

Ubuntu / Debian

bash
# 1. Remove any old Docker installations
sudo apt-get remove docker docker-engine docker.io containerd runc

# 2. Update package index and install prerequisites
sudo apt-get update
sudo apt-get install -y \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

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

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

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

# 6. Verify the installation
sudo docker run hello-world

CentOS / RHEL / Fedora

bash
# 1. Remove old Docker installations
sudo yum remove docker docker-client docker-client-latest \
    docker-common docker-latest docker-latest-logrotate \
    docker-logrotate docker-engine

# 2. Install prerequisites
sudo yum install -y yum-utils

# 3. Set up the Docker repository
sudo yum-config-manager --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

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

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

# 6. Verify the installation
sudo docker run hello-world

Arch Linux

bash
# Install Docker from the official repository
sudo pacman -S docker docker-compose docker-buildx

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

# Verify
sudo docker run hello-world

Post-Installation Steps (Linux)

Run Docker as a Non-Root User

bash
# Create the docker group (if it doesn't exist)
sudo groupadd docker

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

# Activate the group changes (or log out and back in)
newgrp docker

# Verify you can run Docker without sudo
docker run hello-world

Configure Docker to Start on Boot

bash
# Enable Docker to start on boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

# Disable Docker from starting on boot
sudo systemctl disable docker.service
sudo systemctl disable containerd.service

Configure Docker Daemon

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

json
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2",
  "default-address-pools": [
    {
      "base": "172.17.0.0/16",
      "size": 24
    }
  ],
  "dns": ["8.8.8.8", "8.8.4.4"]
}
bash
# Restart Docker to apply changes
sudo systemctl restart docker

Verify Installation

Regardless of your platform, run these commands to verify Docker is working correctly:

bash
# Check Docker version
docker --version

# Check Docker Compose version
docker compose version

# View system-wide information
docker info

# Run the verification container
docker run hello-world

# Run an interactive container
docker run -it alpine sh
# Inside the container:
# cat /etc/os-release
# exit

Troubleshooting

Common Issues

ProblemPlatformSolution
"Cannot connect to Docker daemon"LinuxRun sudo systemctl start docker
"Permission denied"LinuxAdd user to docker group: sudo usermod -aG docker $USER
WSL 2 not installedWindowsRun wsl --install in PowerShell as admin
Virtualization disabledWindowsEnable VT-x/AMD-V in BIOS settings
Docker Desktop won't startmacOSReset Docker Desktop from troubleshoot menu
Slow performanceWindows/macOSIncrease memory/CPU in Docker Desktop settings

Checking Docker Status

bash
# Linux: Check Docker daemon status
sudo systemctl status docker

# All platforms: Test Docker connectivity
docker info

# Check Docker logs (Linux)
sudo journalctl -u docker.service

Next Steps

基于 MIT 许可发布