6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WindowsのWSL LinuxでPodman v5を使う

Posted at

備忘

検証環境

  • Windows 11 Pro 22H2 (x64)
  • WSL バージョン: 2.1.5.0
  • WSL2上のLinux
    • Fedora Linux 39 (Microsoft StoreからFedora WSLをインストール)

WindowsへのPodman導入

この時点では最新は5.0.2
以下を利用

もしくは以下でも可能と思われる

podman-N.N.N-setup.exeを実行

ダウンロードしたら、EXEファイルを実行する。
新しいターミナルを再起動すると、podman.exeがPATHに含まれ、実行できるようになる。

podman-machine-defaultを作成

C:\Users\hiro> podman machine init
Downloading VM image: v20240418182928-5.0-rootfs-amd64.tar.zst: done
Extracting compressed file: podman-machine-default-amd64: done
Importing operating system into WSL (this may take a few minutes on a new WSL install)...
インポート中です。この処理には数分かかることがあります。
この操作を正しく終了しました。
Configuring system...
Machine init complete
To start your machine run:

        podman machine start

podman-machine-defaultを起動

machine initが完了したら、必要に応じて起動や停止ができる

C:\Users\hiro> podman machine start
Starting machine "podman-machine-default"

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: npipe:////./pipe/docker_engine

Docker API clients default to this address. You do not need to set DOCKER_HOST.
Machine "podman-machine-default" started successfully

Windowsからのpodman run 実行例1

dateコマンドを実行

C:\Users\hiro> podman run --rm ubi8-micro date
Resolved "ubi8-micro" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull registry.access.redhat.com/ubi8-micro:latest...
Getting image source signatures
Checking if image destination supports signatures
Copying blob sha256:0e019b285e0d2979b67152f7e92e6947d6189d4998135c97b6dbd8f598bbc0de
Copying config sha256:438fe6a3ad1ca5de05ca5447d58a34d9fd30d730670c654af72b110ec4fbbb0d
Writing manifest to image destination
Storing signatures
Thu Apr 18 22:32:53 UTC 2024

初回のみpullメッセージが表示される
podman image rmにてイメージが削除されない限り、以降はdate情報のみ出力される

Windowsからのpodman run 実行例2

helloを実行

C:\Users\hiro> podman -r run --rm quay.io/podman/hello
Trying to pull quay.io/podman/hello:latest...
Getting image source signatures
Copying blob sha256:ca510d053fa331685272237d370529c6b09d3c6cfb9370a7dca78f71b2cf7531
Copying config sha256:acab2e9fc0d96e289148c38852c1626d1ca97b806d643c7b85f910609f5f8c2e
Writing manifest to image destination
!... Hello Podman World ...!

         .--"--.
       / -     - \
      / (O)   (O) \
   ~~~| -=(,Y,)=- |
    .---. /`  \   |~~
 ~/  o  o \~~~~.----. ~~
  | =(X)= |~  / (O (O) \
   ~~~~~~~  ~| =(Y_)=-  |
  ~~~~    ~~~|   U      |~~

Project:   https://github.com/containers/podman
Website:   https://podman.io
Desktop:   https://podman-desktop.io
Documents: https://docs.podman.io
YouTube:   https://youtube.com/@Podman
X/Twitter: @Podman_io
Mastodon:  @Podman_io@fosstodon.org

WSLの状態(参考)

podman-machine-defaultというWSL環境が起動し、そこで動作するpodmanに接続している。

C:\Users\hiro> wsl -l -v
  NAME                      STATE           VERSION
  podman-machine-default    Running         2
  Fedora                    Running         2

podman system connection list(参考)

接続情報は以下の通り

C:\Users\hiro> podman system connection list
Name                         URI                                                          Identity                                                      Default     ReadWrite
podman-machine-default       ssh://user@127.0.0.1:55918/run/user/1000/podman/podman.sock  C:\Users\hiro\.local\share\containers\podman\machine\machine  true        true
podman-machine-default-root  ssh://root@127.0.0.1:55918/run/podman/podman.sock            C:\Users\hiro\.local\share\containers\podman\machine\machine  false       true

WSL Linuxにおける設定

WSL2上のLinuxとして、ここでは Fedora Linux 39 を利用
Microsoft StoreからFedora WSLをインストールして起動

podman-remote-static-linux_amd64.tar.gz v5.0.2をダウンロード、解凍、/usr/bin/podmanとして配置

作法として正しいのかわからなかったが、利便性、設定の容易性を考慮して/usr/bin/podmanとして配置

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ wget https://github.com/containers/podman/releases/download/v5.0.2/podman-remote-static-linux_amd64.tar.gz
...
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ ls podman-remote-static-linux_amd64.tar.gz
podman-remote-static-linux_amd64.tar.gz
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ tar zxvf podman-remote-static-linux_amd64.tar.gz
bin/podman-remote-static-linux_amd64
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ sudo mv bin/podman-remote-static-linux_amd64 /usr/bin/podman
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ podman --version
podman version 5.0.2

接続設定

Podman 4.7.0よりWSL Linux側にsocketが共有されているとのこと。

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ ls /mnt/wsl/podman-sockets/podman-machine-default/
podman-root.sock  podman-user.sock

CONTAINER_HOST環境変数にこの情報を設定

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ echo export CONTAINER_HOST=unix:///mnt/wsl/podman-sockets/podman-machine-default/podman-user.sock >> ~/.bashrc
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ source ~/.bashrc
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ echo $CONTAINER_HOST
unix:///mnt/wsl/podman-sockets/podman-machine-default/podman-user.sock

なおconnection listは特に設定していない

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ podman system connection list
Name        URI         Identity    Default     ReadWrite

WSL Linuxからのpodman run 実行例1

dateコマンドを実行

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ podman run --rm ubi8-micro date
Sun Apr 21 06:37:57 UTC 2024

ダウンロードされたイメージが使われるのでpullメッセージはない。

WSL Linuxからのpodman run 実行例2

helloを実行

Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$ podman -r run --rm quay.io/podman/hello
!... Hello Podman World ...!

         .--"--.
       / -     - \
      / (O)   (O) \
   ~~~| -=(,Y,)=- |
    .---. /`  \   |~~
 ~/  o  o \~~~~.----. ~~
  | =(X)= |~  / (O (O) \
   ~~~~~~~  ~| =(Y_)=-  |
  ~~~~    ~~~|   U      |~~

Project:   https://github.com/containers/podman
Website:   https://podman.io
Desktop:   https://podman-desktop.io
Documents: https://docs.podman.io
YouTube:   https://youtube.com/@Podman
X/Twitter: @Podman_io
Mastodon:  @Podman_io@fosstodon.org
Fedora Linux 39 [hiro@DESKTOP-72JFO1B ~]$

参考

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?