Skip to content

Lesson 1.2: Installing Docker

Welcome to the first hands-on lesson! In this lesson, you'll install Docker on your operating system, verify that it's working correctly, and run your very first container. By the end, you'll have a fully functional Docker environment ready for the rest of the course.


Learning Objectives

TIP

By the end of this lesson, you will be able to:

  • Install Docker Desktop on Windows or macOS.
  • Install Docker Engine on Linux.
  • Verify the installation using docker --version and docker info.
  • Run your first container with docker run hello-world.
  • Understand basic Docker commands and their output.

1. Choosing Your Installation Method

Docker provides two main editions:

  • Docker Desktop: For Windows and Mac users. Includes a graphical interface, Kubernetes integration, and all Docker tools.
  • Docker Engine: For Linux users. Installed via package managers, providing the core Docker daemon and CLI.

Choose the section that matches your operating system.


2. Installing Docker on Windows

System Requirements

RequirementSpecification
Windows VersionWindows 10 64-bit: Pro, Enterprise, or Education (Build 15063+) or Windows 11 64-bit
FeaturesHyper-V and Containers Windows features must be enabled
Processor64-bit with Second Level Address Translation (SLAT)
RAM4GB minimum (recommended)

Installation Steps

  1. Download Docker Desktop
    Go to Docker Hub and click "Download for Windows (stable)".

  2. Run the Installer
    Double-click the downloaded Docker Desktop Installer.exe.

    • If prompted, ensure "Use WSL 2 instead of Hyper-V" is checked (recommended for better performance).
    • Follow the wizard and accept the terms.
  3. Restart Your Computer
    After installation, you may be prompted to restart.

  4. Start Docker Desktop
    Docker will start automatically after restart. Look for the Docker whale icon in the system tray (bottom-right).

    • If it doesn't start, launch it from the Start Menu.
  5. Accept the Subscription Agreement
    The first time you open Docker Desktop, you'll be asked to accept the terms. Do so.

  6. Verify Installation
    Open a Command Prompt or PowerShell window and run:

powershell
docker --version

You should see output like Docker version 24.0.7, build afdd53b.

Also run:

powershell
docker info

This shows detailed system information.

Troubleshooting Tips

WARNING

  • If you get an error about WSL 2 not installed, follow the instructions to install the Linux kernel update package from Microsoft.
  • Ensure virtualization is enabled in BIOS.
  • If Hyper-V is required but not enabled, Docker may prompt you to enable it; you can do this via PowerShell as administrator:
    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All

3. Installing Docker on macOS

System Requirements

RequirementSpecification
macOS Version10.15 or newer (Intel or Apple Silicon)
RAMAt least 4GB
VirtualizationEnabled by default on modern Macs

Installation Steps

  1. Download Docker Desktop for Mac
    Visit Docker Hub and click "Download for Mac (stable)".

  2. Open the Disk Image
    Double-click the downloaded Docker.dmg file and drag the Docker icon to the Applications folder.

  3. Launch Docker
    Open Docker from the Applications folder. You may be prompted to allow the application to run; confirm.

  4. Accept the Subscription Agreement
    Read and accept the terms.

  5. Wait for Docker to Start
    The Docker whale icon will appear in the top menu bar. Once it's running, you'll see a green dot indicating it's healthy.

  6. Verify Installation
    Open Terminal and run:

bash
docker --version

Example output: Docker version 24.0.7, build afdd53b

Also run:

bash
docker info

Note for Apple Silicon (M1/M2/M3) Users

INFO

Docker Desktop for Mac includes native support for Apple Silicon. All images built for linux/arm64 will run natively; x86_64 images run via emulation (slower but works).


4. Installing Docker Engine on Linux

Most Linux distributions include Docker in their package repositories, but it's recommended to use Docker's official repository for the latest version.

System Requirements

  • A 64-bit Linux distribution (Ubuntu, Debian, Fedora, CentOS, etc.).
  • Kernel version 3.10 or later.
  • sudo privileges.

Installation on Ubuntu / Debian

  1. Update packages and install prerequisites:
bash
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release
  1. Add Docker's official GPG key:
bash
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  1. Set up the stable repository:
bash
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
  1. Install Docker Engine:
bash
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Start Docker and enable on boot:
bash
sudo systemctl start docker
sudo systemctl enable docker
  1. Verify installation:
bash
sudo docker --version
sudo docker info

Post-installation: Manage Docker as a Non-root User (Optional but Recommended)

WARNING

By default, Docker commands require sudo. To run Docker without sudo, add your user to the docker group:

bash
sudo usermod -aG docker $USER

Log out and log back in (or restart) for changes to take effect. Verify with:

bash
docker --version

Installation on Fedora / RHEL / CentOS

INFO

Similar steps but using dnf or yum. Refer to official documentation.


5. Running Your First Container

Now that Docker is installed, let's run the classic "Hello World" container. This container is a tiny test image that prints a message and exits.

  1. Open a terminal (Command Prompt, PowerShell, or Terminal).

  2. Run the following command:

bash
docker run hello-world
  1. Observe the output. It should look similar to:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:aa0cc8055b...83f5cbd9
Status: Downloaded newer image for hello-world:latest

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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

What Just Happened?

INFO

  • Docker checked if the hello-world image existed locally.
  • Since it didn't, it pulled the image from Docker Hub (the default public registry).
  • Docker created a container from that image.
  • The container ran a simple program that printed the welcome message.
  • The container then exited.

Congratulations! You've just run your first container.


6. Exploring Basic Docker Commands

Let's familiarize ourselves with a few essential commands you'll use often.

CommandDescriptionExample
docker --versionShow Docker versiondocker --version
docker infoDisplay system-wide informationdocker info
docker run <image>Run a container from an imagedocker run hello-world
docker pull <image>Download an image without running itdocker pull ubuntu
docker imagesList downloaded imagesdocker images
docker psList running containersdocker ps
docker ps -aList all containers (including stopped)docker ps -a
docker rm <container>Remove a stopped containerdocker rm 5a3f
docker rmi <image>Remove an imagedocker rmi hello-world

Try a few of these after running hello-world. For example:

bash
docker ps -a

You'll see your hello-world container listed with a status "Exited".


Hands-On Tasks

Complete these tasks to reinforce what you've learned:

  • [ ] Verify your installation by running docker --version and docker info. Note any interesting details from docker info (like number of containers, images, storage driver).

  • [ ] Run the hello-world container (if you haven't already).

  • [ ] List all containers (including stopped ones) and note the container ID and name.

  • [ ] Pull the Ubuntu image:

bash
docker pull ubuntu:latest

Observe the download progress and layers.

  • [ ] List images to see both hello-world and ubuntu.

  • [ ] Remove the hello-world container (use docker ps -a to find its ID or name, then docker rm <id>).

  • [ ] Remove the hello-world image:

bash
docker rmi hello-world
  • [ ] Try running an interactive Ubuntu container:
bash
docker run -it ubuntu bash

You'll be inside the container. Type exit to leave.


Common Issues and Solutions

IssueSolution
"docker: command not found"Docker is not installed or not in your PATH. Revisit installation steps.
"Cannot connect to the Docker daemon"Docker daemon is not running. On Linux, start it with sudo systemctl start docker. On Windows/Mac, ensure Docker Desktop is running (check system tray/menu bar).
Permission denied (Linux)If you didn't add your user to the docker group, prefix commands with sudo, or follow the post-install steps.
WSL 2 issues (Windows)Ensure WSL 2 is properly installed and set as default. Docker Desktop can help configure it.

Summary

Key Takeaways

  • You have successfully installed Docker on your system.
  • You verified the installation and ran the hello-world container.
  • You learned basic Docker commands to manage images and containers.
  • You are now ready to dive deeper into building and running your own containers.

Check Your Understanding

  1. What command do you use to check the installed Docker version?
  2. How do you list all containers (both running and stopped)?
  3. What does the docker run hello-world command do step by step?
  4. Why might you need to use sudo with Docker commands on Linux?
  5. What is the purpose of the docker pull command?
Click to see answers
  1. docker --version
  2. docker ps -a
  3. Docker client sends request to daemon → daemon checks for image locally → pulls from Docker Hub if missing → creates container → runs the hello-world program → outputs message
  4. Docker daemon runs as root; without adding your user to the docker group, you need sudo to communicate with it.
  5. docker pull downloads an image from a registry to your local machine without running it.

Additional Resources


Next Up

In the next lesson, we'll explore Docker architecture in more depth, understanding the client-server model, images, containers, and registries. See you there!