Docker MacOS 安装

参考:使用 Docker Desktop 安装
参考:Colima
由于不太喜欢 Docker Desktop,所以现在使用 Colima 。

Homebrew 安装

由于 MacOS 一般使用 Homebrew 作为包管理工具,所以需要先安装 Homebrew。

参考:清华大学开源软件镜像站

纯命令行快速配置 Homebrew 镜像 + 安装

安装 Xcode 命令行工具

xcode-select --install

一键追加环境变量到 ~/.zprofile

echo 'export HOMEBREW_BREW_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"' >> ~/.zprofile
echo 'export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"' >> ~/.zprofile
echo 'export HOMEBREW_API_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles/api"' >> ~/.zprofile
echo 'export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"' >> ~/.zprofile
echo 'export HOMEBREW_PIP_INDEX_URL="https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"' >> ~/.zprofile
echo 'export HOMEBREW_INSTALL_FROM_API=1' >> ~/.zprofile

立即生效环境变量

source ~/.zprofile

安装 Homebrew

git clone --depth=1 https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/install.git brew-install
/bin/bash brew-install/install.sh
rm -rf brew-install

自动追加 Homebrew 路径

Apple Silicon (arm64) 设备:

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
source ~/.zprofile

Intel (x86_64) 设备:

echo 'eval "$(/usr/local/bin/brew shellenv)"' >> ~/.zprofile
source ~/.zprofile

不确定架构?先执行:

uname -m

使用 Colima + Docker CLI

这是 macOS 上最接近原生体验、无需 Docker Desktop 的方案。

安装

使用 Colima + Docker CLI

安装步骤如下:

# 安装 docker CLI 和 colima
brew install docker colima

# 启动 colima(默认使用 lima + QEMU 启动轻量虚拟机)
#colima start
# 后台运行
brew services start colima

# 查看 colima 状态,启动完成后才能使用 docker 。
colima status

# 验证 docker 是否正常运行
docker run hello-world

优点:

  • 完全不需要 Docker Desktop
  • 不用登录 Docker Hub
  • 更轻量,更可控
  • 支持 GPU、Kubernetes、volume 挂载等功能

配置

在使用 colima 启动的 Docker 环境中,如果你想设置镜像加速器(镜像源地址),需要配置 Docker 的 daemon.json 文件,Colima 有自己的配置机制。

编辑 Colima 的配置文件使镜像源保持一致,配置路径:

~/.colima/default/colima.yaml

修改 docker 字段

原来是

docker:{}

修改为

docker:
  registry-mirrors:
    - https://docker.1ms.run

重启启动 colima

brew services restart colima

验证是否生效

docker info

应该能看到你配置的 Registry Mirrors 地址。

posted @ 2025-06-29 11:20  ioufev  阅读(332)  评论(0)    收藏  举报