Docker DesktopからColimaに乗り換えた

Docker Desktopがアップデート後に起動しなくなったことをきっかけに、CLIベースのコンテナ実行環境であるColimaへ移行しました。Docker ComposeやBuildxの設定、自動起動までの手順を紹介します。

目次

はじめに

最近Docker Desktopがアップデート後に起動しなくなりました。 おそらく v4.70.0 で修正された以下のエラーが原因です。

For Mac

  • Fixed a crash loop where Docker Desktop repeatedly failed to start with exit status 42 after an update due to a corrupted DockerAppLaunchPath setting.
  • Fixed an issue where a failed update could leave Docker Desktop in a broken state. The installer now automatically reverts to the previous version and shows a clear error message.

Docker Desktop release notes より)

以前からDocker Desktopを開いてGUI操作する機会はほとんどなく、より軽量なColimaへの移行を検討していました。 今回Docker Desktopが起動しなくなったことをきっかけに、移行に踏み切りました。

Colima とは

Colimaは、macOS(およびLinux)上でコンテナランタイムを提供する軽量なツールです。 Docker Desktopと異なりGUIを持たず、CLIのみで操作します。

Docker Desktopは、VM管理・Dockerデーモン・Docker CLI・Docker Compose・Buildxなどを一括で提供するオールインワンのアプリケーションです。 一方Colimaが担うのはこのうちVM管理とDockerデーモンの提供部分で、Docker CLIやDocker Composeなどは別途インストールが必要です。

Homebrewで簡単にインストールでき、colima start コマンドひとつでDocker実行環境を立ち上げられます。

作業内容

Docker Desktop のアンインストール

以下のページに従い、Docker Desktopをアンインストールしました。

Uninstall Docker Desktop

Colima・Docker のインストール

以下のページに記載されている通り、Homebrewでインストールします。

Colima

brew install colima

インストール後 colima start を実行すると以下のエラーになりました。

INFO[0001] starting colima
INFO[0001] runtime: docker
FATA[0001] dependency check failed for docker: docker not found, run 'brew install docker' to install

エラーログに従い、Dockerのインストールも行います。

brew install docker

再度 colima start を実行すると、Colimaが起動し、docker コマンドを使えるようになりました。 docker ps コマンドで動作を確認できます。

Docker Compose の設定

Docker ComposeもHomebrew経由でインストールします。

brew install docker-compose

インストール時のログに表示される通り、~/.docker/config.json にプラグインのパスを追加します。

{
"cliPluginsExtraDirs": [
"/opt/homebrew/lib/docker/cli-plugins"
]
}

設定後、docker compose コマンドが使えるようになりました。

docker compose ps

Buildx のインストール

あるリポジトリで docker compose up -d を実行したところ、以下の警告やエラーが表示されました。

WARN[0000] Docker Compose requires buildx plugin to be installed
the --mount option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled

Buildxをインストールして解消します。

brew install docker-buildx

インストール時に cliPluginsExtraDirs の設定を求められますが、Docker Composeのインストール時に対応済みのため追加の作業は不要です。

再度 docker compose up -d を実行したところ、正常にコンテナが立ち上がりました。

Colima の自動起動

以下のコマンドにより、Colimaがログイン時に自動起動するよう設定しました。

brew services start colima

Colima の起動オプションのカスタマイズ

Colimaでは起動時のCPUコア数やメモリ、ディスクサイズなどをカスタマイズできます。 詳細は以下のページを参照してください。

Configuration | Colima

おわりに

Docker Desktopのインストールと比べるとセットアップの手数は多少必要ですが、それでもColimaのセットアップは想像以上に簡単でした。 今後は使用感に応じてColimaの設定を調整しつつ使っていきたいと思います。