Docker CLI on macOS
在 macOS 上使用 Docker CLI 而不依賴 Docker Desktop 的完整指南,適合商業環境或希望使用輕量化解決方案的開發者。
背景與動機
Docker Inc 宣布 Docker Desktop 商業使用不再免費,對企業開發造成影響。主要替代方案包括:
- 付費使用 Docker Desktop
- 改用 Podman - 開源容器引擎
- 使用 Docker CLI + Colima - 本文重點
重要提醒:授權變更只影響 Docker Desktop 產品,CLI 介面對所有使用者仍然免費。
為什麼選擇 Docker CLI + Colima?
- 成本考量:完全免費的開源解決方案
- 相容性:與現有 CI/CD 流程完全相容
- 雲端整合:多數雲端服務仍提供 Docker 環境
- 輕量化:比 Docker Desktop 更節省系統資源
Install docker
macOS 上可以直接用 homebrew 來安裝 docker.
除了 docker 外, 還需要安裝 docker-credential-helper, credential helper 可以用 macOS Keychain 來儲存遠端 repo credential,
brew install docker docker-credential-helper
上面指令安裝了 docker cli 命令程式, 安裝完成後可以看到有 docker 指令不會 command not found, 但 docker ps 仍找不到相關 daemon.
Install colima
真正重要的是提供 contrainer runtime 的服務, macOS 上可選用目前開源且免費的 Colima
brew install colima
從套件相依性可以看到 colima 是以 qemu 核心建構的虛擬框架, 集成許多 open source 專案提供的 container runtime service.
Using colima
安裝完成後把服務啟動
colima start
第一次啟動時需要下載 qemu 影像檔, 靜待下載安裝即可.
服務正常啟動的狀態
colima services
若想讓 colima 服務常駐, 重新開機後能自動啟動, 可利用 brew services
brew services start colima
Docker CLI plugin
Buildx
buildx is a Docker CLI plugin for extended build capabilities with BuildKit.
- Manual download buildx binary from release
- Rename the relevant binary to
docker-buildx - Copy it to the destination
$HOME/.docker/cli-plugins - Enjoy it
See Also
Colima
Colima means Containers in Lima. Since Lima is aka Linux on Mac. By transitivity, Colima can also mean Containers on Linux on Mac.
Colima 額外還支援 Kubernetes 基礎建設, 再另找時間好好研究.