Podman の VM を applehv で作ってみる
macOS の Podman が 4.8 になってた
先日、podmanjp に参加したときに macOS の podman が qemu じゃなくて macos の Hypervisor.framework を使った VM でつかえるようになると聞いた。
そのときはまだ github から持ってきてコンパイルしないとダメだったので、homebrew でインストールした podman を削除して自分でコンパイルしたものを使っていた。
なんですが、ふと homebrew の podman を見ると最新の 4.8 になっていたので、homebrew 版に戻して podman の VM を applehv にしてみました。
準備
applehv を使うためには podman 以外に vfkit をインストールしておく必要がある。gvproxy も必要らしいが、これは podman と一緒にインストールされるはず。(追記: vfkit をインストールするには brew tap で追加しないといけない)
brew tap cfergeau/crc
brew install vfkit
brew install podman
あと、VM を qemu ではなく applehv で起動するために環境変数を設定しておく必要がある。今回は適当に .zshenv に書いておいた。ただ、環境変数で設定すると podman-desktop では使えないので追記した containers.conf に設定しておくのが良いと思う。
export CONTAINERS_MACHINE_PROVIDER=applehv
(追記)
もしくは、macOS の場合は .config/containers/containers.conf の machine table に provider = "applehv" と書いておく。こちらであれば podman-desktop からでも使えるようになる。
[machine]
provider = "applehv"
最後に applehv 用のイメージファイルをダウンロードしておく。イメージファイルは https://fedorapeople.org/groups/podman/testing/applehv で配布されている。自分の macbook は m2 なので arm 用のイメージを適当にダウンロードした。
(2024/1/25 追記)
コメントにて podman 4.9 以降イメージファイルは自動的にダウンロードしてくれると教えていただきました。ですので、今は上記の手順は不要です。
VM 作成、起動
ここまで準備ができればあとは podman machine init すれば applehv で VM が起動する。
init 時には、先程ダウンロードしたイメージファイルを指定するくらい。あとのオプションはお好みで
(2024/1/25 追記)
こちらもイメージファイルは自動的にダウンロードしてくれるようなので、--image-path は不要になります。
❯ podman machine init --image-path=podman/images/fedora-coreos-38.20231107.dev.0-applehv.aarch64.raw.gz --disk-size 30 --cpus 4 --memory 4096
Extracting compressed file: podman-machine-default_fedora-coreos-38.20231107.dev.0-applehv.aarch64.raw: done
Machine init complete
To start your machine run:
podman machine start
作成後は podman machine start で起動できる
❯ podman machine start
Starting machine "podman-machine-default"
WARN[0032] API socket failed ping test
This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:
podman machine set --rootful
API forwarding listening on:
Another process was listening on the default Docker API socket address.
You can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:
export DOCKER_HOST='unix://'
Machine "podman-machine-default" started successfully
起動後に見るとこんな感じ。VM TYPE が applehv になっている
❯ podman machine ls
NAME VM TYPE CREATED LAST UP CPUS MEMORY DISK SIZE
podman-machine-default applehv About a minute ago Currently running 4 4GiB 30GiB
これで今までと同じように使えるはず。気をつける点として、podman desktop からはまだ使えないので podman desktop からはもうしばらく待たないといけない。環境変数で applehv を設定すると podman-desktop からは使えないが、containers.conf のほうに設定しておくと podman-desktop からでも使えた。
Endpoint が applehv 用のディレクトリ内の podman.sock になっている。

podman 4.8 は他にも podman farm で異なるCPUアーキテクチャを一つのイメージManifestとして管理できるようになったようなのでこれも後で試してみる。