Installing Docker Desktop

Week 1, Wednesday - Morning Session

Lecture Overview

Today we'll walk through the installation process for Docker Desktop - the comprehensive development environment that enables you to build, share, and run containerized applications. By the end of this session, you'll have Docker installed and ready to use, regardless of your operating system. We'll cover installation on Windows, macOS, and Linux, along with common troubleshooting steps and best practices.

What is Docker Desktop?

Before diving into installation, let's understand what Docker Desktop is and why it's valuable for developers.

Docker Desktop is an integrated development environment for Docker that runs on your local machine. It provides:

Analogy: If Docker Engine is like a car's engine, Docker Desktop is the complete vehicle with a dashboard, controls, fuel system, and amenities. It packages everything you need into a user-friendly experience, making it much easier to get started.

Docker Desktop abstracts away many of the complexities of container management, especially on Windows and macOS where Docker can't run natively (since it depends on Linux kernel features). Docker Desktop sets up a lightweight virtual machine behind the scenes to host the Docker Engine.

System Requirements

Before installation, make sure your system meets the minimum requirements:

Windows Requirements

macOS Requirements

Linux Requirements

Note: System requirements may change with newer versions of Docker Desktop. Always check the official Docker Desktop documentation for the most up-to-date requirements.

Installing Docker Desktop on Windows

The installation process for Windows involves a few key steps to ensure Docker runs properly with either WSL 2 or Hyper-V.

Step 1: Enable Required Windows Features

First, you need to enable either WSL 2 (recommended) or Hyper-V:

Option A: Setting Up WSL 2 (Recommended)
  1. Open PowerShell as Administrator
  2. Run the following command to enable WSL:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  3. Enable Virtual Machine feature:
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  4. Restart your computer
  5. Download and install the WSL 2 Linux kernel update package
  6. Set WSL 2 as your default version:
    wsl --set-default-version 2
Option B: Enable Hyper-V (Alternative)
  1. Open Control Panel > Programs > Turn Windows features on or off
  2. Check the boxes for:
    • Hyper-V
    • Containers
  3. Click OK and restart your computer

Step 2: Download and Install Docker Desktop

  1. Download Docker Desktop for Windows from the official Docker website
  2. Double-click the installer (.exe) file
  3. Follow the installation wizard instructions
    • Accept the terms and conditions
    • Choose whether to use WSL 2 or Hyper-V backend
    • Select additional configuration options
  4. Click "Close and restart" when prompted

Step 3: Verify Installation

  1. After restart, Docker Desktop should start automatically (look for the Docker icon in the system tray)
  2. Open a command prompt or PowerShell window
  3. Run the following command to verify Docker is installed and running:
    docker --version
    docker run hello-world

Example Output:

C:\Users\username> docker --version
Docker version 24.0.2, build cb74dfc

C:\Users\username> docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...
Common Windows Installation Issues
  • BIOS Virtualization not enabled: Enter your computer's BIOS settings on startup and enable virtualization (may be called VT-x, AMD-V, or Virtualization Technology)
  • WSL 2 installation incomplete: Follow the WSL 2 installation guide from Microsoft
  • System requirements not met: Check if your Windows version is supported
  • Port conflicts: Docker uses ports 80, 443, and others that might conflict with existing services like IIS

Real-world context: On Windows, Docker Desktop integrates with WSL 2, which provides better performance than the older Hyper-V backend. This is especially noticeable when working with file mounts and networking. Many professional developers prefer using Docker with WSL 2 and a Linux distribution like Ubuntu for a more Linux-native experience while still using Windows as their primary OS.

Installing Docker Desktop on macOS

Docker Desktop installation on macOS is relatively straightforward, but there are differences between Intel and Apple Silicon (M1/M2) Macs.

Step 1: Download Docker Desktop

  1. Visit the Docker Desktop for Mac download page
  2. Download the appropriate version:
    • For Intel Macs: Docker Desktop for Mac with Intel Chip
    • For M1/M2 Macs: Docker Desktop for Mac with Apple Silicon

Step 2: Install Docker Desktop

  1. Open the downloaded .dmg file
  2. Drag the Docker icon to the Applications folder
  3. Open Docker from your Applications folder
  4. You may be prompted to provide administrator permissions
  5. The Docker menu icon will appear in the status bar when Docker Desktop is running

Step 3: Verify Installation

  1. Open Terminal
  2. Run the following commands to verify Docker is installed and running:
    docker --version
    docker run hello-world

Example Output:

$ docker --version
Docker version 24.0.2, build cb74dfc

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete
Digest: sha256:fc6cf906cbfa013e80938cdf0bb199fbdbb86d6e3e013783e5a766f50f5dbce0
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.
...
Special Considerations for Apple Silicon (M1/M2) Macs

Docker Desktop for Apple Silicon runs containers built for both ARM64 and x86_64 architectures through emulation. However, there are some performance considerations:

  • Native ARM64 images run faster than emulated x86_64 images
  • You may encounter compatibility issues with some x86_64-specific containers
  • Specify platform when pulling images that need to run with emulation:
    docker pull --platform linux/amd64 image-name
  • Many popular images now provide multi-architecture support, automatically using the right version for your CPU
Common macOS Installation Issues
  • Permissions issues: Make sure to allow Docker in System Preferences > Security & Privacy after installation
  • Resource constraints: Docker Desktop's default memory allocation might be too low; increase it in Preferences > Resources
  • Networking conflicts: Issues with VPNs or other networking software can interfere with Docker's networking
  • Rosetta 2 not installed (M1/M2 Macs): Some features may require Rosetta 2 for translation

Real-world context: On macOS, Docker Desktop creates a lightweight virtual machine behind the scenes (using Apple's Hypervisor framework), since Docker requires Linux kernel features. This is completely transparent to you as a user but explains why Docker uses more resources on macOS than it might on a native Linux installation.

Installing Docker Desktop on Linux

Docker Desktop for Linux is relatively new compared to Windows and macOS versions. Many Linux users traditionally used the standalone Docker Engine, but Docker Desktop provides a more consistent experience across platforms.

Step 1: Set up Docker's Repository

These instructions are for Ubuntu, but similar steps apply for other distributions.

  1. Update your package index:
    sudo apt-get update
  2. Install required packages:
    sudo apt-get install ca-certificates curl gnupg
  3. 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
    sudo chmod a+r /etc/apt/keyrings/docker.gpg
  4. Set up the 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

Step 2: Download and Install Docker Desktop

  1. Download Docker Desktop for your Linux distribution from the Docker Desktop for Linux page
  2. For Debian-based distributions like Ubuntu, install with:
    sudo apt-get update
    sudo apt-get install ./docker-desktop-<version>-<arch>.deb
  3. For RPM-based distributions like Fedora:
    sudo dnf install ./docker-desktop-<version>-<arch>.rpm
  4. Start Docker Desktop:
    systemctl --user start docker-desktop

Step 3: Verify Installation

  1. Open a terminal
  2. Run the following commands to verify Docker is installed and running:
    docker --version
    docker run hello-world
Alternative: Install Docker Engine Only

Many Linux users prefer to install just the Docker Engine without the Desktop application:

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

This provides all the core Docker functionality without the GUI and some additional features of Docker Desktop.

Common Linux Installation Issues
  • Missing dependencies: Make sure to install all required packages
  • Permission issues: Users need to be in the docker group to run Docker commands without sudo:
    sudo usermod -aG docker $USER
    newgrp docker
  • Conflicting Docker installations: If you previously installed Docker Engine, you might need to remove it before installing Docker Desktop
  • Desktop environment compatibility: Docker Desktop requires a supported desktop environment like GNOME or KDE

Real-world context: On Linux, Docker can run natively without virtualization, which gives it a performance advantage over Windows and macOS. Many production servers run Linux specifically because of this native container support. In professional settings, understanding both Docker Desktop and the standard Docker Engine installation is valuable.

Docker Desktop Configuration

After installing Docker Desktop, it's important to configure it according to your needs. The configuration options are largely the same across all platforms, accessible through the Docker Desktop application.

Essential Configuration Options

  1. Resources:
    • CPU allocation - How many CPU cores Docker can use
    • Memory - How much RAM to allocate (2GB minimum recommended)
    • Disk image size - Maximum size of Docker's virtual disk
    • Swap - Additional virtual memory
  2. File sharing / Resources > File sharing:
    • Configure which directories can be mounted into containers
    • Essential for mounting source code and other local files
  3. Network:
    • Port mapping - Which ports can be published to the host
    • VPN and proxy settings
  4. Docker Engine:
    • Advanced configuration via a JSON file
    • Allows customizing daemon options
  5. Kubernetes:
    • Enable/disable Kubernetes
    • Configure Kubernetes options

Example Docker Engine configuration:

{
  "registry-mirrors": [
    "https://mirror.gcr.io"
  ],
  "insecure-registries": [
    "registry.local:5000"
  ],
  "experimental": false,
  "features": {
    "buildkit": true
  }
}

Recommended Resource Configuration for Development:

  • CPUs: At least half of your available cores
  • Memory: 4GB minimum, 8GB+ recommended for complex applications
  • Swap: 1GB minimum
  • Disk image: 60GB+ for development work

Docker Desktop vs. Docker Engine

It's important to understand the distinction between Docker Desktop and Docker Engine, especially for those who might be transitioning between different systems.

Feature Docker Desktop Docker Engine
Graphical User Interface Yes No
Operating System Support Windows, macOS, Linux Linux (natively), Windows Server
Virtualization Layer Yes (on Windows and macOS) No (runs natively on Linux)
Docker Compose Included Separate installation
Kubernetes Included Separate installation
Developer Tools Dashboard, extensions, dev environments Command-line only
Resource Usage Higher (due to VM) Lower
Typical Use Case Development environments Production servers

Analogy: Docker Desktop is like a fully-equipped kitchen with modern appliances, a digital interface, and preset cooking programs. Docker Engine is more like a professional gas range - more powerful and efficient but requiring more expertise to use effectively. Both can cook the same meals, but they offer different experiences in getting there.

For most development purposes, especially when learning Docker, Docker Desktop is recommended for its ease of use and integrated tools. However, understanding the underlying Docker Engine becomes important when working with production environments or Linux servers.

Docker Desktop Components

Docker Desktop includes several key components that work together to provide a comprehensive development environment:

Core Components

Optional Components

┌─────────────────────────────────────────────────┐
│              Docker Desktop Application           │
│                                                   │
│  ┌─────────────┐  ┌─────────────┐  ┌───────────┐ │
│  │  Dashboard  │  │ Kubernetes  │  │Extensions │ │
│  └─────────────┘  └─────────────┘  └───────────┘ │
│                                                   │
│  ┌─────────────────────────────────────────────┐ │
│  │           Virtualization Layer              │ │
│  │      (WSL2/Hyper-V/HyperKit/KVM)           │ │
│  └─────────────────────────────────────────────┘ │
│                                                   │
│  ┌───────────┐ ┌────────────┐ ┌────────────────┐ │
│  │   Docker  │ │   Docker   │ │     Docker     │ │
│  │   Engine  │ │  Compose   │ │    BuildKit    │ │
│  └───────────┘ └────────────┘ └────────────────┘ │
└─────────────────────────────────────────────────┘

Understanding these components helps you make the most of Docker Desktop and troubleshoot issues when they arise.

Docker Desktop Licensing

It's important to be aware of Docker's licensing terms, which have changed in recent years:

Current Licensing Structure

Note: Licensing terms may change over time. Always check the official Docker pricing page for the most current information.

For this course and most personal projects, the free personal license will be sufficient. However, it's good to be aware of the licensing requirements if you plan to use Docker in a professional or enterprise setting.

Docker in the Development Workflow

Now that you have Docker Desktop installed, let's briefly explore how it fits into a typical development workflow:

Basic Development Workflow with Docker

  1. Create a Dockerfile - Define your application environment
  2. Build an image - Package your application and dependencies
  3. Run containers - Test your application in isolation
  4. Use Docker Compose - Coordinate multiple services (e.g., web app, database)
  5. Iterate rapidly - Make changes and rebuild as needed
  6. Share images - Push to a registry for collaboration or deployment
Python-Specific Workflow Example

For Python web development, a typical workflow might look like:

  1. Create a Dockerfile for your Python application:
    FROM python:3.10-slim
    
    WORKDIR /app
    
    COPY requirements.txt .
    RUN pip install --no-cache-dir -r requirements.txt
    
    COPY . .
    
    CMD ["python", "app.py"]
  2. Create a docker-compose.yml for local development:
    version: '3'
    
    services:
      web:
        build: .
        ports:
          - "5000:5000"
        volumes:
          - .:/app
        depends_on:
          - db
        environment:
          - DATABASE_URL=postgresql://postgres:password@db:5432/myapp
    
      db:
        image: postgres:13
        volumes:
          - postgres_data:/var/lib/postgresql/data
        environment:
          - POSTGRES_PASSWORD=password
          - POSTGRES_DB=myapp
    
    volumes:
      postgres_data:
  3. Start your development environment:
    docker-compose up
  4. Make code changes, and they're automatically reflected in the running container (thanks to the volume mount)

This workflow allows you to develop in an environment that's identical to production, eliminating "works on my machine" problems and making collaboration easier.

Testing Your Docker Installation

Let's verify that Docker is working correctly by running a few basic commands:

Basic Verification Commands

docker --version
docker info
docker run hello-world

More Comprehensive Test

Let's run a more interactive container to ensure everything is working properly:

docker run -it --rm ubuntu bash

This command runs an Ubuntu container and gives you a bash shell inside it. You can run commands like:

ls -la
apt-get update
echo "Docker is working!"
exit

The container will be automatically removed when you exit (due to the --rm flag).

Testing Docker Compose

docker-compose --version

If all these commands work without errors, your Docker installation is functioning correctly!

Troubleshooting Common Installation Issues

Even with a straightforward installation process, you might encounter some issues. Here are solutions to common problems:

General Issues

Windows-Specific Issues

macOS-Specific Issues

Linux-Specific Issues

Diagnostic information: When troubleshooting, the Docker Desktop logs can be extremely helpful. You can access them from the Docker Desktop menu or in the following locations:

  • Windows: %APPDATA%\Docker\log.txt
  • macOS: ~/Library/Containers/com.docker.docker/Data/log/vm.log
  • Linux: ~/.docker/desktop/log/

Docker Desktop Alternatives

While Docker Desktop is the recommended solution for most developers, it's worth knowing about alternatives:

Alternative Container Solutions

For this course, we'll focus on Docker Desktop as it provides the most consistent experience across all platforms and has the best integration with development workflows.

Key Takeaways

With Docker Desktop successfully installed, you're ready to start building, running, and sharing containerized applications!

Looking Ahead

In our afternoon session, we'll dive into using Docker with practical examples. We'll cover:

Make sure your Docker Desktop installation is working correctly before the afternoon session.

Discussion Questions

  1. What challenges do you anticipate in incorporating Docker into your development workflow?
  2. How might Docker Desktop improve collaboration among developers with different operating systems?
  3. What kind of applications do you think would benefit most from containerization?
  4. What are the security implications of running Docker on your development machine?
  5. How does the resource allocation for Docker Desktop impact your system, and how would you optimize it?

Additional Resources