Skip to main content
Docker Basics Tutorial
CHAPTER 02 Beginner

Installing Docker on Windows, Linux, and macOS

Updated: May 15, 2026
15 min read

# CHAPTER 2

Installing Docker on Windows, Linux, and macOS

1. Introduction

Before we can begin packaging our applications into standardized containers, we must prepare our local development environment. Installing Docker used to be a highly complex process requiring deep Linux kernel knowledge. Today, Docker provides incredibly smooth installation packages for every major operating system. In this chapter, we will guide you through installing Docker Desktop for Windows and Mac, as well as the native Docker Engine for Linux, ensuring your system is ready for containerization.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Understand the system requirements for running Docker.
  • Install Docker Desktop on Windows (using WSL2).
  • Install Docker Desktop on macOS (Intel and Apple Silicon).
  • Install the native Docker Engine on a Linux distribution.
  • Verify your installation using the Docker CLI.

3. Beginner-Friendly Explanation

Imagine installing a high-tech video game console.
  • Linux: Docker was built natively for Linux. Installing Docker on Linux is like plugging a PlayStation directly into a TV. It is native, direct, and highly efficient.
  • Windows and Mac: Because Docker requires Linux features to run, Windows and Mac cannot run it natively. When you install "Docker Desktop" on a Mac or Windows PC, Docker secretly installs a tiny, invisible Linux machine in the background. It acts as an adapter, allowing your Mac/Windows computer to play Linux container "games" flawlessly.

4. Docker Desktop vs. Docker Engine

  • Docker Desktop: A massive, all-in-one GUI (Graphical User Interface) application for Mac and Windows. It includes the Docker Daemon, the Docker CLI, Docker Compose, and a visual dashboard to click and view your containers.
  • Docker Engine: The raw, command-line-only version of Docker, traditionally installed on Linux servers in production environments. It has no graphical interface.

5. Installing on Windows (The WSL2 Requirement)

To run Docker on Windows 10/11, your computer must use WSL2 (Windows Subsystem for Linux). This is a massive improvement over older virtualization methods.
  1. 1. Download Docker Desktop for Windows from the official Docker website.
  1. 2. Run the installer. Ensure the box "Use WSL 2 instead of Hyper-V" is checked!
  1. 3. Restart your computer.
  1. 4. When Docker Desktop launches, it may prompt you to install a WSL2 kernel update from Microsoft. Follow the link provided, install the small update, and click Restart in Docker Desktop.

6. Installing on macOS

Docker supports both older Intel Macs and newer Apple Silicon (M1/M2/M3) Macs.
  1. 1. Download Docker Desktop for Mac (Choose the correct chip version: Intel or Apple Silicon).
  1. 2. Open the .dmg file and drag the Docker icon into your Applications folder.
  1. 3. Open Docker from your Applications. It will ask for permission to install networking components (requires your Mac password).
  1. 4. Look at the top menu bar of your Mac. You will see a small "Whale" icon. When the whale stops animating, Docker is running!

7. Installing on Linux (Ubuntu Example)

Linux does not need the heavy "Docker Desktop" GUI. You install the raw Engine via the terminal.
bash
1234567891011121314151617
# 1. Update your package lists
sudo apt-get update

# 2. Install prerequisites
sudo apt-get install ca-certificates curl gnupg

# 3. Add Docker's official GPG encryption 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 docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

8. Mini Project: Verify Your Docker Installation

Let's ensure the Docker Daemon is awake and communicating with your CLI.

Step-by-Step Tutorial:

  1. 1. Open your Terminal (Mac/Linux) or PowerShell/Command Prompt (Windows).
  1. 2. Type the following command to check the version:

bash
1
docker --version

*(You should see something like: Docker version 24.0.5, build ced3990)*

  1. 3. Now, let's run the universal Docker test:

bash
1
docker run hello-world
  1. 4. Docker will download a tiny test image, run it, print a welcoming message to your screen ("Hello from Docker!"), and immediately shut the container down. Your installation is perfect!

9. Real-World Scenarios

In the real world, developers use Docker Desktop on their local laptops to write and test code visually. However, when the code is deployed to the cloud (like an AWS EC2 instance), the DevOps engineer will install the raw, headless Linux Docker Engine to save RAM and CPU resources.

10. Best Practices

  • Linux Post-Installation (The sudo Problem): By default, on Linux, you must type sudo docker run... every single time. To fix this, you must add your user to the docker group. Run: sudo usermod -aG docker $USER. Then log out and log back in. You can now run Docker commands without sudo.

11. Common Mistakes

  • Hardware Virtualization Disabled: On Windows, if Docker Desktop refuses to start and gives a "Virtualization must be enabled" error, you must restart your physical computer, enter your motherboard's BIOS settings, and turn on CPU Virtualization (Intel VT-x or AMD-V).

12. Exercises

  1. 1. What is the fundamental difference between Docker Desktop and the Docker Engine?
  1. 2. Why does Windows require WSL2 (Windows Subsystem for Linux) to run Docker efficiently?

13. FAQs

Q: Is Docker Desktop free? A: Docker Desktop is free for personal use, education, and small businesses. However, for large enterprise companies (more than 250 employees OR more than $10 million in revenue), Docker Desktop requires a paid subscription. (The raw Linux Docker Engine remains 100% free and open-source for everyone).

14. Interview Questions

  • Q: Explain how Docker achieves cross-platform compatibility. How can a container built for Linux run on a macOS laptop?
  • Q: Describe the purpose of the hello-world Docker image. What background processes occur when you execute docker run hello-world for the very first time?

15. Summary

In Chapter 2, we successfully prepared our local development environments. We navigated the installation nuances between Windows, macOS, and Linux. We established that Windows and Mac require the Docker Desktop GUI and a hidden Linux micro-VM, whereas Linux runs the raw Docker Engine natively. Finally, we executed our very first Docker command, verifying our installation with the universal hello-world test container.

16. Next Chapter Recommendation

Our computer is armed with the Docker Engine. It is time to learn how to download pre-built software and run it. Proceed to Chapter 3: Docker Images and Containers.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·