DEV Community

Cover image for Podman 4.3 on Artix Linux: インストール
nabbisen
nabbisen

Posted on • Edited on • Originally published at scqr.net

Podman 4.3 on Artix Linux: インストール

はじめに

Podman は仮想化環境を構築するためのコンテナ管理ツールです。Red Hat 社 によって開発され、Apache ライセンス v2.0 の下、オープンソースソフトウェア (OSS) として 公開 されています。Go 言語 で実装されています。

以前に書いた通り、クロスプラットフォームに対応しており、Docker と高い互換性を持つように意識して開発されています。

この記事では Podman を Artix Linux にインストールする流れを示します。Arch Linux をベースにしていて、systemd を使っていない OS です。

環境

チュートリアル

* doas (OpenDoas) のところは代わりに sudo も使えます。

Pacman でインストール

Arch Linux のパッケージ・マネジメント・システムのおかげで、pacman を使えばシンプルなコマンドで Podman を手に入れられます。

$ doas pacman -Sy podman 
Enter fullscreen mode Exit fullscreen mode

以下のように出力されて、たずねられるでしょう。私はデフォルトを選びました:

:: Synchronizing package databases... (...) resolving dependencies... :: There are 3 providers available for container-network-stack: :: Repository galaxy 1) cni-plugins :: Repository community 2) cni-plugins 3) netavark Enter a number (default=1): 
Enter fullscreen mode Exit fullscreen mode

この後は以下のように出力されました:

looking for conflicting packages... Packages (14) catatonit-0.1.7-2 cni-plugins-1.2.0-2 conmon-1:2.1.5-1 containers-common-1:0.50.1-2 criu-3.17.1-1 crun-1.7.2-1 libslirp-4.7.0-1 nftables-1:1.0.6-1 protobuf-c-1.4.1-1 python-protobuf-21.12-1 python-six-1.16.0-6 slirp4netns-1.2.0-1 yajl-2.1.0-5 podman-4.3.1-2 Total Download Size: 30.62 MiB Total Installed Size: 177.23 MiB :: Proceed with installation? [Y/n] y 
Enter fullscreen mode Exit fullscreen mode

インストールが始まります。出力は以下の通りでした:

:: Retrieving packages...  podman-4.3.1-2-x86_64 16.2 MiB 2.51 MiB/s 00:06 [#################################] 100%  (...)  Total (14/14) 30.6 MiB 1457 KiB/s 00:22 [#################################] 100% (14/14) checking keys in keyring [#################################] 100% (...) (14/14) checking available disk space [#################################] 100% :: Processing package changes... ( 1/14) installing catatonit [#################################] 100% (...) (14/14) installing podman [#################################] 100% Optional dependencies for podman apparmor: for AppArmor support btrfs-progs: support btrfs backend devices [installed] cni-plugins: for an alternative container-network-stack implementation [installed] podman-compose: for docker-compose compatibility podman-docker: for Docker-compatible CLI :: Running post-transaction hooks... (1/1) Creating temporary files... 
Enter fullscreen mode Exit fullscreen mode

Kernel パラメーターを確認

kernel.unprivileged_userns_clone が有効化されている必要があります。

unprivileged_userns_clone に 1 がセットされていることを確認しましょう。0 ではいけません:

sysctl kernel.unprivileged_userns_clone 
Enter fullscreen mode Exit fullscreen mode

出力は以下の通りでした:

kernel.unprivileged_userns_clone = 1 
Enter fullscreen mode Exit fullscreen mode

OK ですね。

QEMU をインストール

Podman 仮想マシンを操作するためには、QEMU が必要です。これは "オープンソースの汎用 マシン Emulator (エミュレーター) ならびに Virtualizer (ヴァーチュアライザー)" です。

こちらも Pacman で入手できます。インストールしましょう:

$ doas pacman -Sy qemu-base 
Enter fullscreen mode Exit fullscreen mode

以下のように出力され、たずねられます。デフォルトを選択すれば OK です:

:: Synchronizing package databases... (...) :: There are 2 providers available for libwolfssl.so=35-64: :: Repository world 1) wolfssl :: Repository extra 2) wolfssl Enter a number (default=1): 
Enter fullscreen mode Exit fullscreen mode

出力は以下の通りでした:

looking for conflicting packages... Packages (44) capstone-4.0.2-6 dtc-1.6.1-4 edk2-ovmf-202211-3 libcacard-2.7.0-2.1 libnfs-5.0.2-1 liburing-2.3-1 multipath-tools-0.9.4-1 numactl-2.0.16-1 qemu-audio-spice-7.2.0-3 qemu-block-curl-7.2.0-3 qemu-block-dmg-7.2.0-3 qemu-block-nfs-7.2.0-3 qemu-block-ssh-7.2.0-3 qemu-chardev-spice-7.2.0-3 qemu-common-7.2.0-3 qemu-hw-display-qxl-7.2.0-3 qemu-hw-display-virtio-gpu-7.2.0-3 qemu-hw-display-virtio-gpu-gl-7.2.0-3 qemu-hw-display-virtio-gpu-pci-7.2.0-3 qemu-hw-display-virtio-gpu-pci-gl-7.2.0-3 qemu-hw-display-virtio-vga-7.2.0-3 qemu-hw-display-virtio-vga-gl-7.2.0-3 qemu-hw-s390x-virtio-gpu-ccw-7.2.0-3 qemu-hw-usb-host-7.2.0-3 qemu-hw-usb-redirect-7.2.0-3 qemu-hw-usb-smartcard-7.2.0-3 qemu-img-7.2.0-3 qemu-pr-helper-7.2.0-3 qemu-system-x86-7.2.0-3 qemu-system-x86-firmware-7.2.0-3 qemu-tools-7.2.0-3 qemu-ui-curses-7.2.0-3 qemu-ui-opengl-7.2.0-3 qemu-ui-spice-app-7.2.0-3 qemu-ui-spice-core-7.2.0-3 qemu-virtiofsd-7.2.0-3 seabios-1.16.1-1 snappy-1.1.9-2 spice-0.15.1-1 usbredir-0.13.0-1 vde2-2.3.3-3 virglrenderer-0.10.4-1 wolfssl-5.5.4-1 qemu-base-7.2.0-3 Total Download Size: 30.00 MiB Total Installed Size: 138.25 MiB :: Proceed with installation? [Y/n] y :: Retrieving packages...  edk2-ovmf-202211-3-any 15.2 MiB 2.11 MiB/s 00:07 [#################################] 100%  (...)  Total (44/44) 30.0 MiB 528 KiB/s 00:58 [#################################] 100% (44/44) checking keys in keyring [#################################] 100% (...) (44/44) checking available disk space [#################################] 100% :: Processing package changes... ( 1/44) installing numactl [#################################] 100% (...) (44/44) installing qemu-base [#################################] 100% Optional dependencies for qemu-base qemu-audio-alsa: for ALSA audio driver (...) qemu-virtiofsd: for virtio-fs shared filesystem daemon [installed] samba: for SMB/CIFS server support :: Running post-transaction hooks... (1/5) Creating system user accounts... Creating group 'qemu' with GID 973. Creating user 'qemu' (QEMU user) with UID 973 and GID 973. (2/5) Creating temporary files... (3/5) Reloading device manager configuration... (4/5) Updating icon theme caches... (5/5) Updating the desktop file MIME type cache... 
Enter fullscreen mode Exit fullscreen mode

トラブルシューティング

QEMU base を上のようにインストールすることで、以下のエラーを回避できるはずです:

$ podman machine init Error: exec: "qemu-system-x86_64": executable file not found in $PATH 
Enter fullscreen mode Exit fullscreen mode

他の依存パッケージのインストール

Arch Linux の Podman wiki によると、fuse-overlayfs すなわち "FUSE 向け overlayfs 実装" と、slirp4netns すなわち "特権の無いネットワーク名前空間用のユーザーモード・ネットワーキング" のインストールが必要です。

後者は Podman インストール時に入ります。しかし前者は違います。そのためここで前者をインストールしましょう:

$ doas pacman -Sy fuse-overlayfs 
Enter fullscreen mode Exit fullscreen mode

出力は以下の通りでした:

:: Synchronizing package databases... (...) resolving dependencies... looking for conflicting packages... Packages (1) fuse-overlayfs-1.10-1 Total Installed Size: 0.11 MiB :: Proceed with installation? [Y/n] y (...) (1/1) installing fuse-overlayfs [#####################################] 100% 
Enter fullscreen mode Exit fullscreen mode

Podman の設定

containers.conf

Artix は systemd を使いません。そこで Podman のコンテナにそのことを伝える必要があります。設定ファイルを編集しましょう:

$ # バックアップの作成 $ doas cp -p /etc/containers/containers.conf /etc/containers/containers.conf.org  $ # 編集 $ doas nvim /etc/containers/containers.conf 
Enter fullscreen mode Exit fullscreen mode

[engine] セクションに以下のように記述します:

 #cgroup_manager = "systemd" + cgroup_manager = "cgroupfs" 
Enter fullscreen mode Exit fullscreen mode

uid / gid

Podman はデフォルトで rootless (ルートレス) モードで動きます。そのための ユーザー / グループ を用意しておきましょう。

/etc/subuid/etc/subgid がそのための設定ファイルです。ログインユーザーの定義を以下のような感じで追加します:

+ {your-user}:100000:65536 
Enter fullscreen mode Exit fullscreen mode

Podman システムのマイグレーション

以下を実行します:

$ podman system migrate 
Enter fullscreen mode Exit fullscreen mode

出力は以下の通りでした:

WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers 
Enter fullscreen mode Exit fullscreen mode

ワーニングが出ています。これは Containersbuildah が無いためです。事前にインストールしておくことで回避できます。

仮想マシンの初期設定

さあ、podman で最初の仮想マシンを作成できるようになりました !! 以下を実行しましょう:

$ podman machine init 
Enter fullscreen mode Exit fullscreen mode

出力は以下の通りでした:

Downloading VM image: fedora-coreos-37.20230110.2.0-qemu.x86_64.qcow2.xz: done Extracting compressed file Image resized. Error: exec: "timedatectl": executable file not found in $PATH 
Enter fullscreen mode Exit fullscreen mode

上のエラーは、OpenRC には systemd の timedatectl という Timezone をカスタマイズする (英語) ためのものが無いためです。 😅

現状はどんな感じなのでしょうか ?
仮想マシンはつくられましたが、仮想マシンが使うイグニッション・ファイルは上で出たエラーのためにつくられていません。
常にというではありませんが、致命的なものになることもあります。修正した方が良いです。別の記事でその方法を書く予定です。

コンテナ・イメージの操作

さてここまでで、コンテナ・イメージをホスティング・サービスから pull できるようになっています。例として Alpine Linux を Docker Hub から pull してみましょう。最も人気のあるイメージの一つですね:

$ podman pull docker.io/alpine 
Enter fullscreen mode Exit fullscreen mode

得られましたか 😉 ? 私が実行した時の出力は以下の通りでした:

Trying to pull docker.io/library/alpine:latest... Getting image source signatures Copying blob (...) Copying config (...) Writing manifest to image destination Storing signatures (...) 
Enter fullscreen mode Exit fullscreen mode

もう少し便利にすることも

余談ですが docker.io/ 部分を省きたければ、registries.conf を編集すれば良いです:

$ # バックアップの作成 $ doas cp -p /etc/containers/registries.conf /etc/containers/registries.conf.org  $ # 編集 $ doas nvim /etc/containers/registries.conf 
Enter fullscreen mode Exit fullscreen mode

末尾に以下の行を追加します:

+ [registries.search] + registries = ['docker.io'] 
Enter fullscreen mode Exit fullscreen mode

テスト用の Web サーバーを実行

修正した方が良い問題をいくつか残しつつも、Podman を使う準備が完了しました。コンテナを実行して遊んでみましょう。

Alpine で動く Apache httpd サーバーを pull しましょう:

$ podman pull docker.io/httpd:alpine 
Enter fullscreen mode Exit fullscreen mode

取得できたら以下を実行します:

$ podman run -p 8080:80 httpd:alpine 
Enter fullscreen mode Exit fullscreen mode

ブラウザで http://127.0.0.1:8080 にアクセスしてみましょう。
こんなふうに表示されるのでは無いでしょうか... 😄

podman コンテナ: httpd が動作しています

おわりに

Podman にはセキュリティや安定性の観点からの配慮が施されています。まず Podman はデーモンを使用しません。そのため仮想マシン上のあるコンテナが他のコンテナに悪影響を及ぼすことが、起こりにくくなっています。またルート権限を必要としないコンテナがデフォルトになっています。そのためコンテナの実行がより安全に行えるようになっています。

Podman で再利用性と独立性の高い環境を築いて、開発生産性の向上や運用環境の改善につなげられると良いですね。

Top comments (0)