Docker Desktop
Windows / macOS 上装 Docker Desktop,以及它的资源限制与常见坑。
Key PointsDocker Desktop 在 Windows/macOS 上跑一个轻量虚拟机来承载 Linux 内核,容器实际跑在那台 VM 里。
装什么
| Platform | Backend | Note |
|---|---|---|
| Windows 11 | WSL 2 | Recommended; needs virtualization enabled |
| Windows 10 | WSL 2 or Hyper-V | WSL 2 needs build 19041+ |
| macOS (Apple silicon) | Apple Virtualization | Pick the Apple Silicon build |
| macOS (Intel) | HyperKit | Older 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 installDocker 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.
装什么
| 平台 | 后端 | 说明 |
|---|---|---|
| Windows 11 | WSL 2 | 推荐;需开启虚拟化 |
| Windows 10 | WSL 2 或 Hyper-V | WSL 2 需 19041+ |
| macOS(Apple 芯片) | Apple 虚拟化框架 | 选 Apple Silicon 版本 |
| macOS(Intel) | HyperKit | 较旧版本 |
安装后验证
Bash
docker version
docker run --rm hello-world
docker info | grep -i "operating system"资源限制
Desktop 的容器跑在 VM 里,CPU、内存、磁盘都是 VM 的额度,不是整机。内存给太小会出现容器被 OOM kill 却查不到原因的情况。
Bash
# macOS/Linux 上看 VM 分到多少资源
docker info | grep -E "CPUs|Total Memory"文件挂载的性能
把宿主目录挂进容器(bind mount)时,macOS/Windows 需要跨 VM 文件系统同步,大量小文件读写会明显变慢。把代码放在 WSL 的 Linux 文件系统里(\\wsl$),或者用 named volume,能快一个数量级。
Bash
# 慢:代码放在 Windows 盘符下
docker run -v /c/Users/me/app:/app node:20 npm install
# 快:代码放在 WSL 的 ext4 里
docker run -v ~/app:/app node:20 npm installDocker Desktop 对商业公司(员工 > 250 或年收入 > 1000 万美元)需要付费订阅。替代方案:Windows 上直接用 WSL 2 里的 Docker Engine,macOS 上用 colima / OrbStack。