Docker on Linux means Docker Engine — a lightweight, command-line native installation. Docker on macOS and Windows means Docker Desktop — a GUI application that runs a Linux VM under the hood.
Here’s how to install both correctly.
Install Docker on Ubuntu / Debian Linux
The cleanest method is through Docker’s official apt repository.
Step 1: Remove old versions
sudo apt-get remove docker docker-engine docker.io containerd runc
Step 2: Set up the repository
# Install dependencies
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 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
Step 3: Install Docker Engine
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Step 4: Run Docker without sudo
By default, Docker requires sudo. Add yourself to the docker group to avoid this:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
Log out and back in for the change to take full effect.
Step 5: Verify
docker run hello-world
You should see: Hello from Docker!
Install Docker on macOS
Docker Desktop (official)
Download from docs.docker.com/desktop/install/mac-install.
Choose the right download for your chip:
- Apple Silicon (M1/M2/M3/M4) → Apple Silicon installer
- Intel → Intel chip installer
Double-click the .dmg, drag Docker to Applications, and open it.
Docker Desktop will ask for privileged access on first launch — allow it.
With Homebrew Cask
brew install --cask docker
Then open Docker Desktop from Applications to start the daemon.
Verify
docker --version
docker run hello-world
Install Docker on Windows
Docker Desktop (official)
Requires Windows 10 64-bit (version 1903 or later) or Windows 11.
Download from docs.docker.com/desktop/install/windows-install.
Run the installer. It will:
- Enable WSL 2 (Windows Subsystem for Linux) if not already enabled
- Install the WSL 2 Linux kernel update
- Configure Docker to use WSL 2 backend
After install, restart your machine.
With winget
winget install Docker.DockerDesktop
Restart after installation, then open Docker Desktop from the Start menu.
Verify
Open PowerShell or Command Prompt:
docker --version
docker run hello-world
Docker Compose
Docker Compose is included in modern Docker installations as a plugin:
docker compose version
If you’re on an older install that uses the standalone docker-compose command, update to Docker Engine 20.10+ to get the plugin version.
Common first commands
# Pull an image
docker pull nginx
# Run a container
docker run -d -p 8080:80 nginx
# List running containers
docker ps
# List all containers (including stopped)
docker ps -a
# Stop a container
docker stop <container_id>
# Remove a container
docker rm <container_id>
# List images
docker images
# Remove an image
docker rmi <image_name>
# Open a shell inside a running container
docker exec -it <container_id> bash
Run a quick web server to test
docker run -d -p 8080:80 --name test-nginx nginx
Open http://localhost:8080 in your browser. You should see the Nginx welcome page.
Clean up when done:
docker stop test-nginx
docker rm test-nginx
Updating Docker
Ubuntu:
sudo apt update && sudo apt upgrade docker-ce
macOS / Windows: Docker Desktop updates itself. Check for updates in the Docker Desktop menu → Check for Updates.
Once Docker is running, see the Docker Cheat Sheet for the commands you’ll use every day, or learn How to Write a Production Dockerfile for Node.js.
Related Articles
Deepen your understanding with these curated continuations.
How to Install Python on Ubuntu, macOS and Windows
Learn how to install Python 3 on Ubuntu, macOS, and Windows using pyenv and Homebrew. Includes setup for pip, virtual environments, and version switching.
How to Install VS Code on Ubuntu, macOS and Windows
Install Visual Studio Code on any OS using apt, Snap, Homebrew, or winget — with the essential extensions every developer should add first.
How to Install Git on Ubuntu, macOS and Windows
Install Git on any operating system — apt, Homebrew, or the official installer — plus first-time configuration, SSH setup, and verifying your install.