🚣‍♀️

Docker on Lima を M1 mac で試してみる

2024/06/15に公開

概要

Docker Desktop for Mac にヘイトが溜まってきたので速いという噂の Lima を使いたい。
公式から yaml を取ってくる方法がうまくいかなかったので別の方法で試した

Lima

https://lima-vm.io/

Lima launches Linux virtual machines with automatic file sharing and port forwarding (similar to WSL2).

mac上で軽量&楽にLinuxを建てられる優れもの。WSL2と同じような使い方ができると思っておいて良さそう
詳しくは https://lima-vm.io/docs/

手順

インストールなど

$ brew install lima docker docker-compose
$ mkdir -p ~/.docker/cli-plugins
$ ln -sfn /usr/local/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
$ limactl -v

公式から引っ張ってきたyamlを使ってみると

$ curl -o docker.yaml https://raw.githubusercontent.com/lima-vm/lima/v0.8.3/examples/docker.yaml

$ limactl start ./docker.yaml
? Creating an instance "docker" Proceed with the current configuration
INFO[0006] Starting the instance "docker" with VM driver "qemu"
INFO[0006] QEMU binary "/opt/homebrew/bin/qemu-system-aarch64" seems properly signed with the "com.apple.security.hypervisor" entitlement
INFO[0006] Attempting to download the image              arch=aarch64 digest= location="https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-arm64.img"
FATA[0007] failed to download "https://cloud-images.ubuntu.com/impish/current/impish-server-cloudimg-arm64.img": unexpected HTTP status Not Found, body="<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL was not found on this server.</p>\n<hr>\n<address>Apache/2.4.29 (Ubuntu) Server at cloud-images.ubuntu.com Port 443</address>\n</body></html>\n"

ダメだった

$ limactl start --name=build --arch=x86_64 --tty=false --mount-writable template://docker
INFO[0000] Terminal is not available, proceeding without opening an editor
INFO[0000] Starting the instance "build" with VM driver "qemu"
INFO[0000] Attempting to download the image              arch=x86_64 digest="sha256:32a9d30d18803da72f5936cf2b7b9efcb4d0bb63c67933f17e3bdfd1751de3f3" location="https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-amd64.img"
Downloading the image (ubuntu-24.04-server-cloudimg-amd64.img)
453.00 MiB / 453.00 MiB [-----------------------------------] 100.00% 4.05 MiB/s
INFO[0113] Downloaded the image from "https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-amd64.img"
INFO[0114] [hostagent] hostagent socket created at /Users/sota.higaki/.lima/build/ha.sock
INFO[0116] [hostagent] Using system firmware ("/opt/homebrew/share/qemu/edk2-x86_64-code.fd")
INFO[0116] [hostagent] Starting QEMU (hint: to watch the boot progress, see "/Users/sota.higaki/.lima/build/serial*.log")
INFO[0116] SSH Local Port: 52421
INFO[0116] [hostagent] Waiting for the essential requirement 1 of 4: "ssh"
INFO[0126] [hostagent] Waiting for the essential requirement 1 of 4: "ssh"
INFO[0154] [hostagent] Waiting for the essential requirement 1 of 4: "ssh"
INFO[0164] [hostagent] Waiting for the essential requirement 1 of 4: "ssh"
INFO[0169] [hostagent] The essential requirement 1 of 4 is satisfied
INFO[0169] [hostagent] Waiting for the essential requirement 2 of 4: "user session is ready for ssh"
INFO[0169] [hostagent] The essential requirement 2 of 4 is satisfied
INFO[0169] [hostagent] Waiting for the essential requirement 3 of 4: "sshfs binary to be installed"
INFO[0209] [hostagent] Waiting for the essential requirement 3 of 4: "sshfs binary to be installed"
INFO[0215] [hostagent] The essential requirement 3 of 4 is satisfied
INFO[0215] [hostagent] Waiting for the essential requirement 4 of 4: "/etc/fuse.conf (/etc/fuse3.conf) to contain \"user_allow_other\""
INFO[0224] [hostagent] The essential requirement 4 of 4 is satisfied
INFO[0224] [hostagent] Mounting "/Users/sota.higaki" on "/Users/sota.higaki"
INFO[0224] [hostagent] Mounting "/tmp/lima" on "/tmp/lima"
INFO[0224] [hostagent] Waiting for the optional requirement 1 of 1: "user probe 1/1"
INFO[0224] [hostagent] Forwarding "/run/user/501/docker.sock" (guest) to "/Users/sota.higaki/.lima/build/sock/docker.sock" (host)
INFO[0224] [hostagent] Forwarding "/run/lima-guestagent.sock" (guest) to "/Users/sota.higaki/.lima/build/ga.sock" (host)
INFO[0224] [hostagent] Guest agent is running
INFO[0224] [hostagent] Not forwarding TCP 127.0.0.53:53
INFO[0224] [hostagent] Not forwarding TCP 127.0.0.54:53
INFO[0224] [hostagent] Not forwarding TCP [::]:22
INFO[0264] [hostagent] Waiting for the optional requirement 1 of 1: "user probe 1/1"
INFO[0322] [hostagent] Waiting for the optional requirement 1 of 1: "user probe 1/1"
INFO[0326] [hostagent] The optional requirement 1 of 1 is satisfied
INFO[0326] [hostagent] Waiting for the guest agent to be running
INFO[0326] [hostagent] Waiting for the final requirement 1 of 1: "boot scripts must have finished"
INFO[0332] [hostagent] The final requirement 1 of 1 is satisfied
INFO[0332] READY. Run `limactl shell build` to open the shell.
INFO[0332] Message from the instance "build":
To run `docker` on the host (assumes docker-cli is installed), run the following commands:
------
docker context create lima-build --docker "host=unix:///Users/sota.higaki/.lima/build/sock/docker.sock"
docker context use lima-build
docker run hello-world
------

lima VMの起動に成功した

contextの設定

$ docker context create lima-build --docker "host=unix:///Users/snowindy/.lima/build/sock/docker.sock"
lima-build
Successfully created context "lima-build"
$ docker context use lima-build
lima-build
Current context is now "lima-build"

contextが正しいか確認 limaを使っているはず

$ docker context ls
NAME           DESCRIPTION                               DOCKER ENDPOINT                                          ERROR
default        Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
lima-build *                                             unix:///Users/snowindy/.lima/build/sock/docker.sock

$ docker run --rm hello-world

が通れば lima on Docker 成功。

Discussion