Docker Desktop

Windows / macOS 上装 Docker Desktop,以及它的资源限制与常见坑。

Beginner
Key PointsDocker Desktop 在 Windows/macOS 上跑一个轻量虚拟机来承载 Linux 内核,容器实际跑在那台 VM 里。

装什么

PlatformBackendNote
Windows 11WSL 2Recommended; needs virtualization enabled
Windows 10WSL 2 or Hyper-VWSL 2 needs build 19041+
macOS (Apple silicon)Apple VirtualizationPick the Apple Silicon build
macOS (Intel)HyperKitOlder build

安装后验证

Bash
docker version
docker run --rm hello-world
docker info | grep -i "operating system"

资源限制

Containers run inside a VM, so CPU, memory and disk are the VM's quota, not the host's. Too little memory shows up as containers being OOM-killed with no obvious cause.

Bash
# macOS/Linux 上看 VM 分到多少资源
docker info | grep -E "CPUs|Total Memory"

文件挂载的性能

Bind-mounting a host directory crosses the VM boundary; many small file operations get slow on macOS/Windows. Keep code inside the WSL filesystem or use a named volume for an order-of-magnitude speedup.

Bash
# 慢:代码放在 Windows 盘符下
docker run -v /c/Users/me/app:/app node:20 npm install

# 快:代码放在 WSL 的 ext4 里
docker run -v ~/app:/app node:20 npm install
Docker Desktop requires a paid subscription for larger companies (>250 employees or >$10M revenue). Alternatives: Docker Engine inside WSL 2 on Windows, colima or OrbStack on macOS.

Friends & Partners