Day 2: Installing Docker and First Run

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

  • Install Docker on your operating system
  • Verify your Docker installation is working correctly
  • Run your first Docker container
  • Understand the basic Docker workflow from image to container

1. Welcome and Introduction (5 minutes)

Icebreaker Activity

Yesterday we learned about containers conceptually. Today we’re going hands-on! Have you ever had that excitement of unwrapping a new piece of technology and getting it working for the first time? That’s exactly what we’re doing today with Docker.

Lesson Overview

  • Duration: 60-75 minutes
  • Prerequisites: Completed Day 1, administrative access to your computer
  • Materials Needed: Computer with internet access, administrative privileges

2. Learning Objectives and Session Outline (5 minutes)

What We’ll Cover Today:

  1. Docker Installation - Step-by-step setup for your operating system
  2. Installation Verification - Ensuring everything works correctly
  3. First Container Run - The traditional “Hello World” moment
  4. Understanding the Workflow - What happens when you run a container
  5. Basic troubleshooting - Common installation issues and solutions

Success Criteria:

By the end of this session, you should have Docker running on your machine and have successfully executed your first container.

3. Foundation Knowledge (15-20 minutes)

Core Concepts

Docker Desktop vs. Docker Engine

Docker comes in different flavors depending on your operating system and use case:

Docker Desktop (Windows/macOS):

  • Complete Docker development environment
  • Includes Docker Engine, CLI, Compose, and Kubernetes
  • User-friendly GUI for management
  • Best for development on Windows and macOS

Docker Engine (Linux):

  • Core Docker runtime
  • Command-line interface
  • Typically used on servers and Linux development machines

Real-World Analogy: Think of Docker Desktop as a complete workshop with all tools included, while Docker Engine is like having just the essential power tools for professional work.

System Requirements

Understanding what Docker needs to run helps prevent installation issues:

Windows:

  • Windows 10/11 (64-bit)
  • WSL 2 feature enabled
  • Hyper-V capability
  • 4GB system RAM minimum

macOS:

  • macOS 10.15 or newer
  • Apple chip (M1/M2) or Intel processor
  • 4GB system RAM minimum

Linux:

  • 64-bit kernel version 3.10 or higher
  • Various distributions supported (Ubuntu, CentOS, Debian, etc.)

Key Terminology

  • Docker Desktop: All-in-one Docker application for Windows and macOS
  • Docker Engine: Core Docker runtime that manages containers
  • Docker CLI: Command-line interface for interacting with Docker
  • WSL 2: Windows Subsystem for Linux, required for Docker on Windows
  • Daemon: Background service that manages Docker containers and images

4. Detailed Explanation and Examples (25-30 minutes)

Understanding Docker Installation Components

When you install Docker, you’re actually installing several components that work together:

  1. Docker Engine: The core runtime that creates and manages containers
  2. Docker CLI: The command-line tool you’ll use to interact with Docker
  3. Docker Compose: Tool for defining multi-container applications
  4. Docker Desktop (Windows/macOS): GUI application that includes everything above

The Container Runtime Architecture

[Your Commands] → [Docker CLI] → [Docker Daemon] → [Container Runtime] → [Linux Kernel]

Understanding this flow helps when troubleshooting:

  • Docker CLI receives your commands and sends them to the daemon
  • Docker Daemon manages images, containers, networks, and volumes
  • Container Runtime actually runs the containers using kernel features

Platform-Specific Considerations

Windows with WSL 2: Docker Desktop uses Windows Subsystem for Linux 2 to provide a Linux kernel environment. This is necessary because containers are fundamentally a Linux technology.

macOS: Docker Desktop creates a lightweight Linux virtual machine to run containers. This VM is optimized and mostly invisible to users.

Linux: Docker runs natively since containers are a Linux kernel feature. No additional virtualization layer is needed.

Common Misconceptions

  1. Misconception: Docker requires a virtual machine to run Reality: Only on Windows and macOS. Linux runs containers natively.

  2. Misconception: You need to understand all components before starting Reality: You can start using Docker with just basic CLI knowledge and learn components as needed.

5. Live Coding Demonstration (20-25 minutes)

Example 1: Windows Installation Process

# Step 1: Download Docker Desktop from docker.com
# Step 2: Run installer as administrator
# Step 3: Enable WSL 2 when prompted

# Verify installation
docker --version
# Expected output: Docker version 24.x.x, build xxxxx

docker run hello-world
# Downloads and runs first container

Explanation:

  • docker --version: Confirms Docker CLI is installed and accessible
  • docker run hello-world: Downloads a test image and runs it as a container
  • First run takes longer due to image download

Example 2: macOS Installation Process

# Step 1: Download Docker Desktop from docker.com
# Step 2: Drag Docker.app to Applications folder
# Step 3: Launch Docker from Applications

# Verify installation
docker --version
docker info
# Shows detailed Docker system information

# First container run
docker run hello-world

Key Points:

  • macOS may prompt for system permissions
  • Docker Desktop icon appears in menu bar when running
  • docker info provides more detailed system information

Example 3: Linux Installation (Ubuntu)

# Update package index
sudo apt-get update

# Install required packages
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Set up 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

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

# Add user to docker group (optional, for non-sudo usage)
sudo usermod -aG docker $USER
# Log out and back in for group changes to take effect

# Verify installation
docker --version
sudo docker run hello-world

Understanding the Hello World Container

# Detailed examination of what happens
docker run hello-world

# What this command does:
# 1. Looks for 'hello-world' image locally
# 2. Downloads from Docker Hub if not found
# 3. Creates a new container from the image
# 4. Runs the container's default command
# 5. Container prints message and exits

6. Hands-On Practice (30-40 minutes)

Exercise 1: Complete Docker Installation (20 minutes)

Objective: Install Docker on your specific operating system

Instructions for Windows:

  1. Visit https://docs.docker.com/desktop/windows/install/
  2. Download Docker Desktop for Windows
  3. Run installer as administrator
  4. Restart computer when prompted
  5. Launch Docker Desktop
  6. Complete the tutorial if prompted

Instructions for macOS:

  1. Visit https://docs.docker.com/desktop/mac/install/
  2. Choose appropriate version (Intel or Apple silicon)
  3. Download and install Docker Desktop
  4. Launch Docker Desktop from Applications
  5. Grant necessary permissions when prompted

Instructions for Linux (Ubuntu/Debian):

  1. Follow the official installation guide: https://docs.docker.com/engine/install/ubuntu/
  2. Use the provided commands in the demonstration
  3. Consider adding your user to the docker group
  4. Test with docker run hello-world

Exercise 2: Installation Verification (10 minutes)

Objective: Confirm Docker is working correctly

Verification Steps:

# Check Docker version
docker --version

# Check Docker system information
docker info

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

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# List downloaded images
docker images

Expected Results:

  • Version command shows Docker version
  • Info command shows system details without errors
  • Hello-world container runs and displays welcome message
  • Container appears in docker ps -a with “Exited” status
  • Hello-world image appears in docker images

Exercise 3: Exploring Your First Container (10 minutes)

Objective: Understand what happened during your first container run

Exploration Commands:

# Get detailed information about the hello-world image
docker inspect hello-world

# View the history of the hello-world image
docker history hello-world

# Remove the container (cleanup)
docker rm $(docker ps -aq -f "ancestor=hello-world")

# Remove the image (we'll re-download it later)
docker rmi hello-world

# Run hello-world again to see the download process
docker run hello-world

Questions to Answer:

  1. What happened when you ran the container the second time after removing the image?
  2. How large is the hello-world image?
  3. What command does the hello-world container execute?

7. Common Pitfalls and Troubleshooting (10 minutes)

Frequent Installation Issues

  1. Problem: “Docker Desktop requires Windows 10 Pro or Enterprise” Cause: Older Windows 10 Home versions didn’t support required features Solution: Update to latest Windows 10/11 Home (supports WSL 2) or use Docker Toolbox for older systems

  2. Problem: “WSL 2 installation is incomplete” Cause: Windows Subsystem for Linux not properly configured Solution:

    # Run in PowerShell as Administrator
    wsl --install
    wsl --set-default-version 2
    
  3. Problem: “Permission denied” when running Docker commands (Linux) Cause: User not in docker group or running without sudo Solution:

    # Add user to docker group
    sudo usermod -aG docker $USER
    # Log out and back in, or use:
    newgrp docker
    
  4. Problem: Docker Desktop won’t start on macOS Cause: Insufficient permissions or security settings Solution: Check System Preferences > Security & Privacy > General for blocked apps

Debugging Tips

  • Check Docker Desktop is running: Look for whale icon in system tray/menu bar
  • Restart Docker service: Often resolves temporary issues
  • Check system resources: Docker needs adequate RAM and disk space
  • Review Docker Desktop logs: Help > Troubleshoot > Get support

8. Best Practices and Professional Tips (5 minutes)

Installation Best Practices

  • Use official sources: Always download Docker from docker.com or official repositories
  • Keep Docker updated: Regular updates include security patches and new features
  • Understand resource limits: Configure appropriate CPU and memory limits in Docker Desktop
  • Enable auto-start: Configure Docker to start with your system for development convenience

Development Environment Setup

  • Configure resource allocation: Adjust Docker Desktop settings based on your system capabilities
  • Set up development folders: Consider where you’ll store Docker projects
  • Learn keyboard shortcuts: Docker Desktop provides useful shortcuts for common operations

Next Steps in Your Learning Journey

  • Tomorrow: Understanding Docker architecture and components
  • Week 1 goal: Comfortable with basic Docker commands
  • Month 1 goal: Building and deploying real applications with Docker

9. Summary and Review (5 minutes)

Key Takeaways

  1. Docker installation varies by platform but the end result is the same powerful tooling
  2. The hello-world container demonstrates the complete Docker workflow in miniature
  3. Verification steps ensure your installation is working correctly

Quick Review Questions

  1. What’s the difference between Docker Desktop and Docker Engine?
  2. What does the docker run hello-world command actually do?
  3. How can you verify that Docker is properly installed and running?

Tomorrow’s Preview

Tomorrow we’ll dive deeper into Docker’s architecture and understand the relationship between the Docker daemon, CLI, images, and containers. You’ll learn how these components work together to create the Docker experience.


For Instructors

Teaching Tips

  • Have students install Docker before class if possible, but be prepared for installation issues
  • Keep alternative installation methods ready (Docker Toolbox for older systems)
  • Emphasize that installation problems are normal and part of the learning process
  • Use screen sharing for installation demonstrations

Assessment Ideas

  • Successful completion of installation verification steps
  • Screenshot of docker run hello-world output
  • Troubleshooting exercise with intentionally broken installation

Adaptation Notes

  • For complete beginners: Provide step-by-step screenshots for installation
  • For experienced developers: Focus on understanding differences between platforms
  • Remote learning: Consider pre-recorded installation videos for different platforms
  • In-person classes: Have USBs ready with Docker installers for offline situations

Time Management Suggestions

  • 45-minute session: Focus on installation and verification only
  • 90-minute session: Add troubleshooting workshop and exploration exercises
  • Workshop format: Pair students for peer support during installation

Common Student Questions

Q: “Why does Docker need so many system resources?” A: Docker Desktop includes development tools and a Linux VM (on Windows/macOS). Production Docker is much lighter.

Q: “Do I need Docker Desktop for development?” A: On Windows/macOS, yes. On Linux, you can use Docker Engine directly, but Docker Desktop provides useful development features.

Q: “Can I run Docker in a virtual machine?” A: Yes, but you’ll need nested virtualization support and it may impact performance.