MacOS Docker 安装
macOS 上装 Docker Desktop(含 Apple 芯片版),以及 colima 这个轻量替代。
Key PointsApple 芯片要装 arm64 版本;不想用 Desktop 的话,colima 用 Lima 起一台轻量 VM,命令行就能管。
Docker Desktop
Bash
brew install --cask docker
open -a Docker # 首次启动要授权
docker run --rm hello-world不用 Desktop:colima
Bash
brew install colima docker docker-compose
colima start --cpu 4 --memory 8 --disk 60
docker context lsApple 芯片的镜像架构
Apple silicon pulls arm64 images; amd64-only images run under Rosetta, which is slower and occasionally crashes. Pin the platform explicitly, or build multi-arch with buildx.
Bash
docker run --platform linux/amd64 --rm hello-world
docker buildx build --platform linux/amd64,linux/arm64 -t me/app:1.0 --push .常见问题
| Symptom | Cause | Fix |
|---|---|---|
Cannot connect to the Docker daemon | Desktop not started | open -a Docker / colima start |
exec format error | Wrong arch image | --platform linux/arm64 |
| Very slow builds | Files on the shared mount | Use a named volume for caches |
Docker Desktop
Bash
brew install --cask docker
open -a Docker # 首次启动要授权
docker run --rm hello-world不用 Desktop:colima
Bash
brew install colima docker docker-compose
colima start --cpu 4 --memory 8 --disk 60
docker context lsApple 芯片的镜像架构
Apple 芯片默认拉 arm64 镜像;只有 amd64 版本时会走 Rosetta 模拟,慢且偶发崩溃。可以显式指定平台,或让 buildx 构建多架构镜像。
Bash
docker run --platform linux/amd64 --rm hello-world
docker buildx build --platform linux/amd64,linux/arm64 -t me/app:1.0 --push .常见问题
| 现象 | 原因 | 处理 |
|---|---|---|
| 连不上守护进程 | Desktop 没启动 | open -a Docker / colima start |
| 格式错误 | 镜像架构不对 | --platform linux/arm64 |
| 构建很慢 | 文件在共享挂载上 | 缓存目录用 named volume |