Learn how to install and use Docker on Windows, Ubuntu, and macOS, along with platform differences, setup steps, and best practices.
Docker on Windows, Ubuntu, and macOS: A Complete Guide
Introduction
Containers have become the backbone of modern application development. And at the heart of containers lies Docker — a tool that lets you build, ship, and run applications consistently across different environments.
Whether you’re coding on Windows, Ubuntu (Linux), or macOS, Docker provides a consistent developer experience.
But there are platform-specific differences in how Docker works, and it’s important to understand them.
In this guide, we’ll explore:
- What Docker is and why it’s useful.
- Installing Docker on Windows, Ubuntu, and macOS.
- Key differences between platforms.
- Best practices for cross-platform Docker development.
1. Why Docker?
Traditional development often runs into the classic:
“But it works on my machine!”
With Docker, you package your app and dependencies into a container image that runs the same way anywhere.
Benefits:
- Consistency across dev, staging, and production.
- Lightweight compared to virtual machines.
- Works with any language or framework.
- Easy to share with teams using Docker Hub.
2. Installing Docker on Different Platforms
a) Docker on Windows
Windows has two ways to run Docker:
-
Docker Desktop (recommended)
- Works on Windows 10/11 Pro & Enterprise (with WSL2).
- Automatically installs WSL2 (Windows Subsystem for Linux) for running Linux containers.
- Provides a GUI for managing containers.
Steps:
- Download Docker Desktop for Windows.
- Install and enable WSL2 backend.
- Verify with:
docker --version docker run hello-world
-
Docker with Hyper-V or VirtualBox (legacy)
- Older option, less efficient than WSL2.
👉 Most developers should use Docker Desktop with WSL2.
b) Docker on Ubuntu (Linux)
Ubuntu is the most natural home for Docker, since Docker was built for Linux.
Steps:
##### Update packages
sudo apt update
sudo apt upgrade -y
##### Install prerequisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common -y
##### Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker.gpg
##### Add Docker repo
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/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 update
sudo apt install docker-ce docker-ce-cli containerd.io -y
##### Check Docker
docker --version
docker run hello-world
👉 On Ubuntu, Docker runs natively without needing WSL or virtualization. Performance is typically best here.
#### c) Docker on macOS
Since macOS is not Linux, Docker relies on a lightweight Linux VM.
##### Steps:
Download Docker Desktop for Mac https://www.docker.com/products/docker-desktop/
Install using the .dmg file.
Run verification:
```sh
docker --version
docker run hello-world
👉 On Apple Silicon (M1/M2/M3), Docker Desktop now supports ARM images, but some legacy x86 images may require emulation (slower).
3. Key Differences Across Platforms
| Feature | Windows (WSL2) | Ubuntu (Linux) | macOS (VM backend) |
|---|---|---|---|
| Performance | Medium → runs inside WSL2 | High → runs natively | Medium → runs inside VM |
| Ease of Setup | Easy (Docker Desktop) | Manual but straightforward | Easy (Docker Desktop) |
| File System Speed | Slower than Linux | Fastest (native Linux FS) | Slower than Linux FS |
| Best For | Enterprise users, .NET devs | Server environments, cloud workloads | Mac developers, frontend devs |
| Extra Requirement | WSL2 or Hyper-V | None (native) | Lightweight Linux VM |
4. Best Practices for Cross-Platform Docker Development
- Always use Linux containers → most production systems run Linux.
- Prefer multi-arch images (supporting amd64 + arm64) for cross-platform compatibility.
- Use Docker Compose for managing multi-container apps.
- Keep images small → use lightweight base images like alpine.
- For Windows devs: store project files in the Linux WSL filesystem, not the Windows filesystem (faster I/O).
- For macOS: test ARM builds separately to ensure compatibility.
5. Docker Example: Run Nginx Everywhere
To prove Docker works the same across all platforms:
docker run -d -p 8080:80 nginx
Open http://localhost:8080 in your browser → you’ll see the Nginx welcome page. This works the same on Windows, Ubuntu, or macOS.
Conclusion
Docker bridges the gap between different OS environments by standardizing application packaging and runtime.
On Ubuntu, Docker is native and fastest.
On macOS and Windows, Docker uses a VM or WSL2, but provides the same developer experience.
Whether you’re on Windows, Ubuntu, or macOS, Docker ensures your apps are portable, consistent, and production-ready.
Continue Reading