PodmanをWSL2で動かす

はじめに

これまでDocker Desktop for Windowsを使っていたのですが、Linuxでコンテナをホストしたくなったので。環境は下記。

> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

インストール

ほぼ下記ページの記載通り。

www.redhat.com

. /etc/os-release
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/x${NAME}_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/x${NAME}_${VERSION_ID}/Release.key -O Release.key
sudo apt-key add - < Release.key
sudo apt-get update -qq
sudo apt-get -qq -y install podman
sudo mkdir -p /etc/containers
echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf

インストール完了。

$ podman -v
podman version 3.3.1

WSL2固有の設定(ルートレス)

参考にした「Enable Sysadmin」の記事では、podman infoを実行すると、$HOME/.config/containers/libpod.confが作成されるとありますが、私の環境では作成されませんでした。

ということで、普通に手動作成。

mkdir -p $HOME/.config/containers/
touch $HOME/.config/containers/libpod.conf

作成したlibpod.confに下記を記述。

[engine]
events_logger="file"

ひな形は/usr/share/containers/containers.confを参照。

動作確認

https://hub.docker.com/_/hello-worldでハロワ。

$ podman run docker.io/hello-world
Trying to pull docker.io/library/hello-world:latest...
Getting image source signatures
Copying blob 2db29710123e done  
Copying config feb5d9fea6 done  
Writing manifest to image destination
Storing signatures

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.
    (amd64)
 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/

以上。