Sub topic 11
Why containers on macOS and Windows run in a Linux VM
This chapter assumes you know what a kernel is, how a process differs from a program, and the basics of namespaces and cgroups from earlier chapters. It also assumes you can use a terminal on macOS or Windows.
The shared kernel is a Linux kernel
Namespaces and cgroups are features of the Linux kernel. A container is an ordinary process that the kernel isolates and limits. It does not bring its own kernel.
Most container images are built for Linux. They contain Linux executables that make Linux system calls. The macOS kernel (XNU) and the Windows NT kernel have different system call interfaces and have no Linux namespaces or cgroups. A Linux binary cannot run on them directly.
So on a Mac, or on Windows with standard Linux containers, a container tool needs a real Linux kernel to share. The usual solution is to start a small Linux virtual machine and run the containers inside it.
How the pieces fit
Docker Desktop, Podman Machine, Colima, and Rancher Desktop all follow this pattern. The VM is created with the platform's own hypervisor. Each tool uses a different mix:
| Platform | Typical hypervisor layer | What runs inside |
|---|---|---|
| macOS | Apple Virtualization framework or QEMU | A minimal Linux VM |
| Windows with WSL 2 | A lightweight utility VM managed by Hyper-V | A Microsoft-built Linux kernel |
| Windows with Hyper-V backend | Hyper-V | A Linux VM |
The docker command on your Mac is only a client. It sends requests over a socket to a daemon running inside the Linux VM. The daemon creates the containers there.
What you can observe
On Linux, the host and container kernel release match. On macOS or Windows they do not, because the container sees the VM's kernel and not your host's.
uname -r
docker run --rm alpine uname -rOn a Mac, the first command prints a Darwin kernel version. The second prints a Linux version string. The mismatch shows that the container is sharing a kernel, just not the host's kernel.
You can also check the architecture:
docker run --rm alpine uname -mOn an Apple silicon Mac this usually prints aarch64. The VM matches your CPU. An amd64 image then needs emulation or fails, which is a common source of slow or odd behavior.
Consequences you will notice
- Startup cost. The first container launch waits for the VM to boot. After that, containers start quickly.
- Fixed VM resources. The VM has its own CPU and memory allocation. A container's
--memorylimit applies inside that allocation, so a large container can fail even if the host has free memory. - File sharing is slower. Bind mounts of host directories cross the VM boundary through a file-sharing layer such as virtiofs or a network protocol. Heavy I/O on mounted folders is slower than on Linux.
- Networking differs. Published ports are forwarded from the host into the VM. A container's IP address is inside the VM and is not reachable directly from the host.
- Architecture matters. Images must match the VM's CPU architecture or run under emulation.
The two-layer model
This setup combines both technologies from this tutorial. A VM supplies the Linux kernel and a hardware-level boundary against your host. Containers inside the VM give you lightweight isolation between workloads. The speed and density benefits of containers remain, but they are bounded by the VM's size.
Exercise
You run docker run --rm alpine uname -s on a Mac and get Linux, though uname -s in your own terminal prints Darwin. Why, and which kernel did the container use?
Show answer
The Docker client on the Mac sent the request to a daemon inside a Linux VM, and the container started there. Containers share the kernel of the system they run on, so it used the Linux kernel of that VM, not the macOS kernel.
Exercise
A container started with --memory=8g is killed on a laptop with 32 GB of free RAM, and the Docker VM is configured with 4 GB. What is the likely cause and fix?
Show answer
The container's limit applies inside the VM, which has only 4 GB. The container can't use memory the VM does not have. Increase the VM's memory allocation in the Docker Desktop or Colima settings.