Skip to main content

Installing Docker


Chapter objectives

  • Install Docker on different operating systems
  • Configure Docker correctly
  • Verify the installation
  • Understand Docker Desktop vs Docker Engine

1 - System prerequisites

Minimum configuration

OSCPURAMDisk space
Windows 10/1164-bit4 GB20 GB
macOS 12+Apple Silicon / Intel4 GB20 GB
Linux64-bit2 GB10 GB

Windows: WSL2 required

Docker Desktop on Windows requires WSL2 (Windows Subsystem for Linux 2):

# Vérifier si WSL est installé
wsl --version

# Installer WSL2 si nécessaire
wsl --install

# Redémarrer l'ordinateur

2 - Installation on Windows

Docker Desktop for Windows

Step 1: Download the installer

Go to docker.com/products/docker-desktop and download the Windows installer.

Step 2: Run the installation

1. Double-cliquez sur Docker Desktop Installer.exe
2. Cochez "Use WSL 2 instead of Hyper-V"
3. Cliquez sur "Install"
4. Redémarrez l'ordinateur

Step 3: Configure Docker Desktop

1. Lancez Docker Desktop
2. Acceptez les conditions d'utilisation
3. Complétez la configuration initiale
4. L'icône Docker apparaît dans la barre des tâches

Step 4: Verify the installation

# Ouvrir PowerShell ou CMD
docker --version
docker run hello-world

WSL2 configuration

To use Docker in WSL2:

# Dans le terminal WSL2
docker --version

# Le daemon Docker Desktop est partagé avec WSL2
docker ps

3 - Installation on macOS

Docker Desktop for Mac

Step 1: Download

Step 2: Installation

1. Ouvrez le fichier .dmg téléchargé
2. Glissez Docker dans le dossier Applications
3. Lancez Docker depuis le Launchpad
4. Autorisez l'accès privilégié si demandé

Step 3: Verification

# Ouvrir Terminal
docker --version
docker run hello-world

Resource configuration

Access the settings via Docker Desktop > Settings > Resources:

ResourceRecommendation
CPU2-4 cores
Memory4-8 GB
Swap1-2 GB
Disk60+ GB

4 - Installation on Linux

Ubuntu / Debian

Step 1: Remove old versions

sudo apt-get remove docker docker-engine docker.io containerd runc

Step 2: Install the dependencies

sudo apt-get update
sudo apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release

Step 3: Add the Docker repository

# Ajouter la clé GPG officielle
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Ajouter le 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

Step 4: 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

Step 5: Configure permissions

# Ajouter l'utilisateur au groupe docker
sudo usermod -aG docker $USER

# Appliquer les changements (déconnexion/reconnexion ou)
newgrp docker

Step 6: Verify the installation

docker --version
docker run hello-world

CentOS / RHEL / Fedora

Installation on CentOS/RHEL

# Supprimer les anciennes versions
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

# Installer les dépendances
sudo yum install -y yum-utils

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

# Installer Docker
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Démarrer Docker
sudo systemctl start docker
sudo systemctl enable docker

# Permissions utilisateur
sudo usermod -aG docker $USER

Installation on Fedora

# Installer le repository
sudo dnf -y install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

# Installer Docker
sudo dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Démarrer et activer
sudo systemctl start docker
sudo systemctl enable docker

Quick installation script (all distributions)

# Script officiel Docker (non recommandé pour production)
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Ajouter l'utilisateur au groupe docker
sudo usermod -aG docker $USER

5 - Post-installation

Configure automatic startup

Linux (systemd)

# Activer Docker au démarrage
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

# Vérifier le statut
sudo systemctl status docker

Configure the Docker daemon

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

{
"storage-driver": "overlay2",
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
},
"default-address-pools": [
{
"base": "172.17.0.0/16",
"size": 24
}
]
}

Restart Docker:

sudo systemctl restart docker

Configure a registry mirror (optional)

To speed up downloads:

{
"registry-mirrors": [
"https://mirror.gcr.io",
"https://docker-mirror.example.com"
]
}

6 - Verifying the installation

Basic tests

# Version
docker --version
# Docker version 24.0.7, build afdd53b

# Version détaillée
docker version

# Informations système
docker info

# Test hello-world
docker run hello-world

More complete test

# Lancer un conteneur interactif
docker run -it ubuntu bash

# Dans le conteneur
cat /etc/os-release
exit

# Lancer un serveur web
docker run -d -p 8080:80 nginx

# Vérifier que nginx répond
curl http://localhost:8080

# Arrêter le conteneur
docker stop $(docker ps -q)

Diagnostic commands

# Lister les conteneurs
docker ps -a

# Lister les images
docker images

# Espace disque utilisé
docker system df

# Événements en temps réel
docker events

7 - Docker Desktop vs Docker Engine

Comparison

FeatureDocker DesktopDocker Engine
Graphical interfaceYesNo
Supported OSesWindows, macOS, LinuxLinux only
Built-in KubernetesYesNo
ExtensionsYesNo
LicensePaid for enterprisesFree
UsageDevelopmentProduction

When to use what?

Docker Desktop

  • Local development on Windows/macOS
  • Need for a graphical interface
  • Teams < 250 people

Docker Engine

  • Linux servers in production
  • CI/CD pipelines
  • Kubernetes clusters

8 - Common troubleshooting

Error: permission denied

# Problème
Got permission denied while trying to connect to the Docker daemon socket

# Solution
sudo usermod -aG docker $USER
newgrp docker
# OU déconnexion/reconnexion

Error: daemon not running

# Linux
sudo systemctl start docker
sudo systemctl status docker

# Vérifier les logs
sudo journalctl -u docker.service

Error: port already in use

# Trouver le processus utilisant le port
sudo lsof -i :80
# OU
sudo netstat -tlnp | grep :80

# Arrêter le processus ou utiliser un autre port
docker run -p 8080:80 nginx

Error: no space left on device

# Nettoyer les ressources inutilisées
docker system prune -a

# Nettoyer les volumes
docker volume prune

# Vérifier l'espace
docker system df

Windows: WSL2 problems

# Redémarrer WSL
wsl --shutdown

# Mettre à jour WSL
wsl --update

# Vérifier la version
wsl --version

Summary

PlatformRecommended method
WindowsDocker Desktop + WSL2
macOSDocker Desktop
Ubuntu/DebianDocker Engine via apt
CentOS/RHELDocker Engine via yum
FedoraDocker Engine via dnf
Key points
  • Docker Desktop for development (Windows/macOS)
  • Docker Engine for production (Linux)
  • Always add the user to the docker group
  • Configure automatic startup on servers

Hands-on exercises

  1. Install Docker on your system
  2. Verify the installation with docker run hello-world
  3. Run an nginx container and access it via the browser
  4. Check the system information with docker info

← Introduction | Docker Images →