Skip to main content

Installing Docker on Various Platforms

Introduction

Now that you understand the fundamentals of Docker and containerization, the next step is to get Docker running on your machine. Docker supports a variety of operating systems and provides different installation methods tailored for each. In this lesson, we'll walk you through installing Docker on the most popular platforms: Windows, macOS, and Linux. You'll also learn about post-installation steps, verifying your setup, and troubleshooting common issues.


Table of Contents

  1. Docker Editions: Community vs. Enterprise
  2. Installing Docker on Windows
  3. Installing Docker on macOS
  4. Installing Docker on Linux (Ubuntu example)
  5. Verifying Your Installation
  6. Common Installation Pitfalls
  7. Summary
  8. Quiz

Docker Editions: Community vs. Enterprise

Docker offers two main editions:

  • Docker Community Edition (Docker CE): Free, open-source, suitable for individuals and teams starting out.
  • Docker Enterprise Edition (Docker EE): Paid, includes additional security, management, and support features for enterprises.

In this course, we'll focus on Docker CE, which provides all the core features you need for development.


Installing Docker on Windows

Requirements

  • Windows 10/11 64-bit: Pro, Enterprise, or Education (Build 15063 or later) with Hyper-V and WSL 2 support.
  • Windows Home: WSL 2 backend is required.

Installation Steps

1. Download Docker Desktop

Go to the Docker Desktop for Windows page and download the installer.

2. Run the Installer

Double-click the downloaded .exe file and follow the prompts.

3. Configuration

  • For Windows Home: The installer will guide you to enable the Windows Subsystem for Linux (WSL 2) and Virtual Machine Platform features.
  • For Pro/Enterprise: Hyper-V is used by default; ensure it's enabled in Windows Features.

4. Start Docker Desktop

After installation, launch Docker Desktop from the Start menu.

5. Verify Installation

Open a new Command Prompt or PowerShell window and run:

docker --version

Expected output (version may vary):

Docker version 24.0.2, build cb74dfc

Use Case

Docker Desktop provides a graphical interface, easy container management, and seamless Kubernetes integration for local development on Windows.


Installing Docker on macOS

Requirements

  • macOS 11+ (Big Sur) or later recommended.
  • Apple Silicon (M1/M2) and Intel chips are supported.

Installation Steps

1. Download Docker Desktop

Go to the Docker Desktop for Mac page. Choose the version for your architecture (Intel/Apple Silicon).

2. Install Docker Desktop

  • Open the downloaded .dmg file.
  • Drag the Docker icon into your Applications folder.

3. Start Docker Desktop

  • Open Docker from the Applications folder.
  • Docker Desktop will start and appear in the menu bar.

4. Verify Installation

Open the Terminal app and run:

docker --version

Expected output:

Docker version 24.0.2, build cb74dfc

Use Case

Docker Desktop on macOS provides a native development environment with GUI tools, automatic updates, and tight integration with the Mac ecosystem.


Installing Docker on Linux (Ubuntu Example)

Docker can be installed on most major Linux distributions. Here, we use Ubuntu 22.04 LTS as an example.

Requirements

  • Ubuntu 20.04/22.04 LTS (or similar)
  • sudo privileges

Installation Steps

1. Uninstall Old Versions

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

2. Update Package Index

sudo apt-get update

3. Install Required Packages

sudo apt-get install \
ca-certificates \
curl \
gnupg

4. 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

5. 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

6. Install Docker Engine

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

7. Start and Enable Docker

sudo systemctl start docker
sudo systemctl enable docker

8. Verify Installation

sudo docker run hello-world

You should see a message confirming that Docker is installed and working.

Optional: Manage Docker as a Non-root User

Add your user to the docker group to run Docker without sudo:

sudo usermod -aG docker $USER
# Log out and log in again for this change to take effect.

Use Case

Installing Docker on Linux is lightweight and gives you granular control, making it ideal for servers, CI/CD runners, and production environments.


Verifying Your Installation

Regardless of your platform, always verify Docker is installed and working by running:

docker run hello-world

Expected output:

Hello from Docker!
This message shows that your installation appears to be working correctly.
...

This command pulls a test image from Docker Hub, runs it in a container, and prints a confirmation message.


Common Installation Pitfalls

1. Virtualization Not Enabled

  • Windows/macOS: Docker Desktop requires virtualization (Hyper-V, WSL 2, or Apple Hypervisor). Check your BIOS/UEFI settings and enable virtualization support.

2. Insufficient Permissions

  • Linux: Running Docker as a non-root user without adding yourself to the docker group results in permission errors.

3. Outdated Packages

  • Linux: Using old versions of Docker or OS packages may cause incompatibility. Always use the official repositories.

4. Conflicting Old Installs

  • Uninstall older Docker versions before installing the latest one to avoid conflicts.

5. Network Issues

  • Docker pulls images from the internet. Ensure your network allows outbound connections to Docker Hub.

Summary

  • Docker supports Windows, macOS, and Linux.
  • Docker Desktop provides a user-friendly GUI for Windows and macOS.
  • Linux installations are more manual but offer more flexibility.
  • Always verify your installation with docker --version and docker run hello-world.
  • Be aware of common installation issues such as virtualization settings, permissions, and conflicting packages.

Quiz

1. What command can you use to verify that Docker is installed and working?

a) docker install check
b) docker verify
c) docker run hello-world
d) docker status

Answer: c) docker run hello-world


2. On Windows Home edition, which backend does Docker Desktop use by default?

a) Hyper-V
b) WSL 2
c) VirtualBox
d) VMware

Answer: b) WSL 2


3. What must you do on Linux to run Docker commands without sudo?

a) Edit the Dockerfile
b) Add your user to the docker group
c) Enable virtualization
d) Install Docker Compose

Answer: b) Add your user to the docker group


4. Why should you uninstall older Docker versions before installing a new one?

a) To free up disk space
b) To avoid compatibility and conflict issues
c) To make installation faster
d) It is not necessary

Answer: b) To avoid compatibility and conflict issues


5. What is a common cause of Docker Desktop failing to start on Windows or macOS?

a) Insufficient RAM
b) Disabled virtualization in BIOS/UEFI
c) Wrong username
d) Too many containers

Answer: b) Disabled virtualization in BIOS/UEFI


You are now ready to start working with Docker images and containers! In the next lesson, we will explore Docker's architecture and its core components.