DOCKER · DOCKER FROM SCRATCH · CHAPTER 9

Docker on Mac and Windows

Linux containers on systems that are not Linux: what sits underneath Docker Desktop.

6 min readCourse: Docker from ScratchLevel: beginner

From point A to point B

Point A: you know that a container shares the host's kernel and that almost every image is Linux, yet many people work on Mac or Windows and Docker works just the same. How is that possible? Point B: by the end of this chapter you will understand what sits underneath Docker Desktop, choose how to install it on your machine, know when Windows containers make sense and know the license terms before you use it in a company.

The problem: a container needs the kernel of its own system

In chapter 1 you saw the key difference from a virtual machine: a container brings no operating system of its own, it uses the host's kernel. An Ubuntu or Alpine image needs a Linux kernel underneath.

Neither Windows nor macOS has a Linux kernel. The solution is the same in both cases: run a small Linux virtual machine and put Docker inside it. Everything else is about making that virtual machine invisible to you.

How Docker Desktop runs on Windows and macOS The docker CLI runs on Windows or macOS and talks to dockerd inside a lightweight Linux VM created with WSL 2, Hyper-V or Apple Virtualization. Containers run on that VM Linux kernel, and published ports are forwarded to localhost on your computer. YOUR COMPUTER · WINDOWS OR macOS docker CLIPowerShell · Terminal localhost:8080your browser LIGHTWEIGHT LINUX VM WSL 2 · Hyper-V · Apple Virtualization dockerdLinux kernel nginx · :80 postgres redis API PORT FORWARDED

The docker client runs on your system; the daemon and the containers run in a lightweight Linux VM. Diagram: The House of Routing.

Before: Docker Toolbox

The first solution was Docker Toolbox: it installed VirtualBox, created a Linux virtual machine with Docker Machine and configured the client to talk to it. It worked, but you could tell: the VM had its own IP, ports were not on localhost and sharing folders was slow.

Docker Toolbox and Docker Machine are retired and no longer maintained. If a tutorial asks you to install them, it is out of date.

Docker Desktop on Windows

Docker Desktop replaces Toolbox with much tighter integration: published ports show up on localhost, folders are shared and the client works in PowerShell just as it does on Linux. For the virtual machine it uses one of these engines:

EngineWhen
WSL 2 (default)The recommended option. It uses the real Linux kernel of the Windows Subsystem for Linux; it needs no administrator rights for a per-user installation.
Hyper-VAn alternative using the Windows hypervisor. It requires an all-users installation, with administrator rights.
# In PowerShell, after installing Docker Desktop
wsl --list --verbose        # you will see the docker-desktop distribution
docker version              # Client: windows/amd64 · Server: linux/amd64
docker run --rm -p 8080:80 nginx:stable

Look at docker version: the client is Windows, but the server is Linux. That is the VM in the figure.

Good to know. Docker Desktop requires 64-bit Windows 10 22H2 or Windows 11 23H2, or later. Windows Server editions are not supported by Docker Desktop.

Windows containers

Since Windows Server 2016 there are also Windows containers: images based on Windows Server Core or Nano Server that use the Windows kernel. They are for packaging applications that only run on Windows, such as classic .NET Framework software or IIS services.

  • A Windows container does not run on Linux, just as a Linux container does not run natively on Windows.
  • In Docker Desktop you switch modes from the icon menu: Switch to Windows containers. It requires Windows 10 or 11 Pro or Enterprise; the Home and Education editions only run Linux containers.
  • In production, Windows containers run natively on Windows Server, with Docker Engine or with containerd.
# In Windows containers mode
docker run --rm mcr.microsoft.com/windows/nanoserver:ltsc2022 cmd /c ver

The vast majority of images, and everything you will see in Kubernetes on this path, are Linux. Use Windows containers only when the application requires them.

Docker Desktop on Mac

On macOS the idea is the same: a lightweight Linux VM, managed by Docker Desktop. To create it, it can use:

  • Apple Virtualization framework: the native macOS virtualization engine, stable and recommended.
  • Docker VMM: a hypervisor optimized for containers, still in beta.
  • HyperKit: the original engine, deprecated. It only exists for Macs with Intel processors, and Docker recommends switching to Apple's framework.

On a Mac with Apple Silicon, the VM is arm64, so the images you pull are for that architecture. If an image only exists for amd64, Docker Desktop can emulate it, more slowly:

docker run --rm alpine:3.22 uname -m                         # aarch64
docker run --rm --platform linux/amd64 alpine:3.22 uname -m  # x86_64, emulated
There are no macOS containers. On a Mac you only run Linux containers. There is no macOS equivalent of Windows containers.

License and alternatives

Docker Engine, the one you installed on Ubuntu in chapter 1, is open source software. Docker Desktop has a different license: it is free for personal use, education, non-commercial open source projects and companies with fewer than 250 employees and less than 10 million dollars in annual revenue (both conditions at once). Larger organizations need a paid subscription.

If the free license does not apply at your company, there are alternatives that keep using the same CLI or a compatible one:

  • Docker Engine inside WSL 2: you install Docker in a WSL Linux distribution, just as on Ubuntu.
  • Colima (Mac) and Rancher Desktop (Mac, Windows, Linux): they create the Linux VM with containerd or Docker Engine.
  • Podman Desktop: another container engine compatible with OCI images.

Before installing on a company machine, ask your IT team which option they have approved.

Cheat sheet: Docker on each system

SystemHow Linux runsNative containers
LinuxDirectly on the host's kernelLinux
Windows 10/11VM on WSL 2 (or Hyper-V)Windows, on Pro and Enterprise
Windows ServerDoes not use Docker DesktopWindows
macOSVM with Apple Virtualization frameworkNone: there are no macOS containers

Challenge

Answer before you open the solution. Getting it wrong here is the cheapest way to learn.

1. Why does Docker Desktop need a virtual machine on Mac and Windows?

Because Linux containers use the host's kernel, and neither macOS nor Windows has a Linux kernel.

2. On Windows, docker version shows the client as windows/amd64 and the server as linux/amd64. Why?

The client runs on Windows; the daemon runs in the Linux VM of WSL 2.

3. A colleague with Windows 11 Home wants to run Windows containers. Can they?

No. Windows containers in Docker Desktop require Windows Pro or Enterprise. With Home they can only run Linux containers.

4. A company with 400 employees wants to use Docker Desktop. Can it do so for free?

No. It exceeds the 250-employee limit; it needs a subscription or an alternative such as Docker Engine on WSL 2.

What you take away

  • Linux containers need a Linux kernel: on Mac and Windows, Docker Desktop creates a lightweight VM.
  • Docker Toolbox and Docker Machine are retired.
  • On Windows, Docker Desktop uses WSL 2 by default, or Hyper-V.
  • Windows containers exist, use the Windows kernel and require Pro or Enterprise.
  • On Mac, the VM uses Apple Virtualization framework; HyperKit is deprecated. There are no macOS containers.
  • Docker Desktop is not free for large companies; Docker Engine is.

In the next chapter, the last one in the course: when one host is not enough. Orchestration with Docker Swarm and Kubernetes.

Official resources

Source and credits. Chapter written from Jesús Espinoza's study notes on KodeKloud's Docker for Absolute Beginners course (December 2024). Text drafted with AI assistance; original diagrams by The House of Routing. Technical details were checked against the official Docker documentation.

Navigate