What You'll Learn
Beginner
- How to install Docker on macOS, Windows, and Linux
- The difference between Docker Desktop and Docker Engine
- How to verify your installation works
- Common installation issues and their fixes
Docker Desktop vs Docker Engine
| Aspect | Docker Desktop | Docker Engine |
|---|---|---|
| Platform | macOS, Windows | Linux |
| Includes | Engine + GUI + Compose + BuildKit | Just the engine (CLI + daemon) |
| License | Free for personal/small orgs; paid for large | Free and open source |
| Architecture | Runs Linux containers in a VM | Runs containers natively |
| Resource usage | Higher (VM overhead) | Lower (native) |
Install on macOS
.dmg filedocker --version to verifyInstall on Windows
Docker Desktop Installer.exedocker --versionInstall on Linux (Ubuntu/Debian)
apt install docker.io) are often outdated.# Update apt and install prerequisites
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
# 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
# Add 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
# Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Post-installation step (Linux only)
By default, only root can run Docker commands. Add your user to the docker group to run without sudo:
sudo usermod -aG docker $USER
# Log out and log back in for changes to take effect
# Or run: newgrp docker
docker group grants root-equivalent privileges. Only do this on a development machine, not on a shared production server.Verify Your Installation
Run these commands to confirm Docker is working:
# 1. Check Docker version
docker --version
# Docker version 24.0.7, build afdd53b
# 2. Check detailed info (client + daemon)
docker version
# 3. Check daemon is running and see system info
docker info
# 4. Run the hello-world container
docker run hello-world
# 5. Check Docker Compose is installed
docker compose version
If docker run hello-world prints a welcome message, your installation is working correctly.
Common Installation Issues
Issue 1: "Cannot connect to the Docker daemon"
Fix (Linux):
sudo systemctl start docker and sudo systemctl enable dockerFix (macOS/Windows): Start Docker Desktop from Applications
Issue 2: "Permission denied" on Linux
docker group.Fix:
sudo usermod -aG docker $USER, then log out and back in.Quick test:
sudo docker run hello-world — if this works, it's a permission issue.
Issue 3: Docker Desktop won't start on Windows
Fix: Run
wsl --install in PowerShell as admin, restart, then wsl --set-default-version 2
Issue 4: Slow on macOS/Windows
Configuration Recommendations
After installing, adjust these Docker Desktop settings (macOS/Windows):
| Setting | Recommended | Why |
|---|---|---|
| Memory | 4-8 GB | Default 2 GB is too low for most apps |
| CPU | 4 cores | More cores = faster builds |
| Swap | 1 GB | For memory-heavy builds |
| Disk image size | 64+ GB | Images accumulate; running out of space breaks Docker |
Common Mistakes
- Using distribution packages on Linux.
apt install docker.ioinstalls an older version. Use Docker's official repository. - Not adding user to docker group on Linux. You'll need
sudofor every command, which is annoying and dangerous for scripts. - Ignoring Docker Desktop resource limits. Default 2 GB RAM is too low for multi-container apps. Increase it.
- Not updating Docker. Old versions have bugs and security issues. Update regularly:
sudo apt upgrade docker-ce(Linux) or auto-update in Desktop settings.
Practical Exercise (10 minutes)
docker --version — confirm it prints a versiondocker run hello-world — confirm you see the welcome messagedocker run -it ubuntu bash — get an interactive shell in Ubuntuapt-get update && apt-get install -y curlcurl https://example.com — you have network access from inside the containerexit to leaveMini Challenge
Run docker info and identify: (1) your Docker version, (2) the storage driver, (3) how many images you have locally, (4) how much disk space Docker is using. Understanding docker info is essential for troubleshooting.
Key Takeaways
- Docker Desktop for macOS/Windows (includes GUI, runs Linux containers in a VM).
- Docker Engine for Linux (native, lighter, free for all uses).
- Always use Docker's official repository on Linux — distribution packages are outdated.
- Add your user to the
dockergroup on Linux to avoidsudo. - Verify with
docker run hello-world— if it prints a welcome message, Docker works.
Today: You installed Docker on your OS and verified it works.
Next: Lesson 06 runs your first real container and explains what happens.
FAQ
Do I need to uninstall old Docker versions first?
On Linux, yes — old versions used different package names (docker, docker-engine). Run sudo apt remove docker docker-engine docker.io containerd runc before installing the new version. On macOS/Windows, Docker Desktop auto-updates.
Can I run Docker without Docker Desktop on macOS?
Technically yes, using colima or podman, but Docker Desktop is the recommended path for most users. Colima is lighter but lacks the GUI and some features.
Comments
Comments
Post a Comment