概要
Nix-darwin で管理している mac で Docker を使えるようにする。
Docker Desktop は業務での使用に懸念があるので、 Colima を使う。
手順
home.nix
Home Manager の設定ファイルに以下を書き加える。
Home Manager を使っていない場合でも、普通に systemPackages
に入れたら動くと思う。
home.nix
{
home.packages = with pkgs;
[
colima
docker
];
}
設定らしい設定は終わり。
VM 起動
colima コマンドで Ubuntu VM を立ち上げて Docker を設定させる。
colima start
→ colima start ~/dotfiles
INFO[0000] starting colima
INFO[0000] runtime: docker
INFO[0000] creating and starting ... context=vm
INFO[0039] provisioning ... context=docker
INFO[0039] starting ... context=docker
INFO[0053] done
docker.sock の権限変更
設定は以上なのだが、このまま起動すると以下のエラーが出て使えない (2024/03/04 時点)。
error during connect: Get "http://%2FUsers%2Fkino-ma%2F.colima%2Fdefault%2Fdocker.sock/v1.24/containers/json": EOF
Colima に issue が上がっており、裏にいる Lima VM の /var/run/docker.sock
の権限が狭いことが原因らしい。
コメント にある通り、以下で解決。
colima ssh -- sudo chmod 666 /var/run/docker.sock
動作確認
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
478afc919002: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(arm64v8)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
おわり。