Podman

提供: ArchWiki
2022年4月15日 (金) 18:34時点におけるKusanaginoturugi (トーク | 投稿記録)による版 (序文に記事を追加)
ナビゲーションに移動 検索に移動

関連記事

Podman は Docker の代わりになるプログラムで、同じようなインターフェイスを提供します。ルートレスコンテナとdocker-compose の shim サービスをサポートします。

インストール

podman パッケージをインストールしてください。コンテナイメージを作成したい場合は Buildah も見てください。

Docker と異なり、Podman はデーモンを必要としませんが、cockpit-podman など cockpit のようなサービスのための API は提供しています。

デフォルトでは Podman を実行できるのは root だけです。root 以外のユーザーでコンテナを実行したい場合はルートレス Podman を参照。

設定

コンテナの挙動を設定する設定ファイルは /usr/share/containers/ にあります。編集する前に /etc/containers にコピーする必要があります。Podman によって使われるネットワークブリッジインターフェイスを設定したいときは /etc/cni/net.d/87-podman-bridge.conflist を見てください。

ルートレス Podman

警告: Rootless Podman relies on the unprivileged user namespace usage (CONFIG_USER_NS_UNPRIVILEGED) which has some serious security implications, see Security#Sandboxing applications for details.

デフォルトではコンテナ (カーネルの文脈で言うところの名前空間) を実行できるのは root だけです。

Podman コンテナを root を使わずに操作したい場合、まずコンテナを使いたいユーザーとグループを決めて、適切なエントリを /etc/subuid/etc/subgid に追加してください。

以下の例では podman ユーザーとグループによる Podman コンテナの実行を有効化します。165536 から 169631 までの UID/GID が podman ユーザー・グループにそれぞれ割り当てられます。詳しくは subuid(5)subgid(5) を見てください。

Enable kernel.unprivileged_userns_clone

First, check the value of kernel.unprivileged_userns_clone by running:

$ sysctl kernel.unprivileged_userns_clone

If it is currently set to 0, enable it by setting 1 via sysctl or kernel parameter.

ノート: linux-hardened has kernel.unprivileged_userns_clone set to 0 by default.

Set subuid and subgid

In order for users to run rootless Podman, a subuid(5) and subgid(5) must be set for each user that wants to use it. These information must, ultimately, be stored in /etc/subuid and /etc/subgid which lists the UIDs for their user namespace.

/etc/subuid and /etc/subgid do not exist by default. If they do not exist yet in your system, create them by running:

# touch /etc/subuid /etc/subgid
ノート: The above command is required, because the usermod used below do not create them.

The following command enables the username user and group to run Podman containers (or other types of containers in that case). It allocates a given range of UIDs and GIDs to the given user and group.

# usermod --add-subuids 100000-165535 --add-subgids 100000-165535 username
ヒント: Instead of using usermod command, this could be achieved either by editing /etc/subuid and /etc/subgid directly.

Now, you should have the following content (replacing username with the given username):

/etc/subuid
username:100000:65536
/etc/subgid
username:100000:65536
ノート: Many images require 65536 uids / gids for mapping (notably the base busybox and alpine images). It is recommended that you allocate at least that many uids / gids for each user to maximize compatibility with docker.

Propagate changes to subuid and subgid

Rootless Podman uses a pause process to keep the unprivileged namespaces alive. This prevents any change to the /etc/subuid and /etc/subgid files from being propagated to the rootless containers while the pause process is running. For these changes to be propagated it is necessary to run:

$ podman system migrate

After this, the user/group specified in the above files is able to start and run Podman containers.

イメージ

ノート: イメージのレジストリプレフィックスは省略できます。Podman は /etc/containers/registries.confregistries.search に定義されている全てのレジストリからイメージを自動で (定義されている順番で) 検索します。以下に記述しているイメージは設定に docker.io がなくても使えるように全てプレフィックスを付けています。

Arch Linux

以下のコマンドで Arch Linux x86_64 イメージが Docker Hub から取得されます。ネットワークなどを除外した縮小版の Arch となっています。

# podman pull docker.io/archlinux

README.md も参照してください。

完全な Arch イメージを使いたい場合、リポジトリを複製して自分自身のイメージを作成してください。

$ git clone https://github.com/archlinux/archlinux-docker.git

devtools パッケージをインストールしてください。

packages ファイルを編集して 'base' とだけ記述し、以下のコマンドを実行:

# make rootfs
# podman build -t archlinux .

Alpine Linux

Alpine Linux はコンテナイメージとして容量が小さく、静的バイナリとしてコンパイルされたソフトウェアに適しています。以下のコマンドで最新の Alpine Linux イメージが Docker Hub から取得されます:

# podman pull docker.io/alpine

Alpine Linux はほとんどの Linux ディストリビューションで使われている glibc libc 実装の代わりに musl libc 実装を使っています。Arch Linux は glibc を使っているため、Arch Linux ホストと Alpine Linux コンテナにはパフォーマンスからソフトウェアの正確性まで様々な影響がある違いが存在します。C ライブラリの差異については こちら に記述されています。

Arch Linux (や glibc を使用する他の環境) で動的リンクでビルドしたソフトウェアは Alpine Linux (や他の libc を使用する環境) で実行したときにバグやパフォーマンスの問題が発生する可能性があります。例としては [1], [2], [3] を見てください。

CentOS

以下のコマンドによって最新の Centos イメージが Docker Hub から取得されます:

# podman pull docker.io/centos

CentOS のリリースを指定するタグについては Docker Hub のページを見てください。

Debian

以下のコマンドによって最新の Debian イメージが Docker Hub から取得されます:

# podman pull docker.io/debian

利用可能なタグについては Docker Hub のページを見てください。各 Debian リリース毎に standard と slim バージョンが存在します。

トラブルシューティング

イメージが見つからない

By default the registry list is not populated as the files in the package come from upstream. This means that by default, trying to pull any image without specifying the registry will result in an error similar to the following:

Error: short-name "archlinux" did not resolve to an alias and no unqualified-search registries are defined in "/etc/containers/registries.conf"

A starting configuration could be the following:

/etc/containers/registries.conf.d/00-unqualified-search-registries.conf
unqualified-search-registries = ["docker.io"]
/etc/containers/registries.conf.d/01-registries.conf
[[registry]]
location = "docker.io"

This is equivalent to the default docker configuration.

コンテナがシェルログアウトで終了する

It may happen that after logging out from machine, Podman containers are stopped. To prevent that, user lingering should be enabled for user running containers:

$ loginctl enable-linger

You can also create user systemd unit as described: https://docs.podman.io/en/latest/markdown/podman-auto-update.1.html#examples

ルートレスモードでブリッジネットワークを使用してコンテナを作成する際にエラー

If you are using AppArmor you might end up with problems when creating container using a bridge network with the dnsname plugin enabled:

$ podman network create foo
/home/user/.config/cni/net.d/foo.conflist
$ podman run --rm -it --network=foo docker.io/library/alpine:latest ip addr
Error: command rootless-cni-infra [alloc 89398a9315256cb1938075c377275d29c2b6ebdd75a96b5c26051a89541eb928 foo festive_hofstadter    ] in container 1f4344bbd1087c892a18bacc35f4fdafbb61106c146952426488bc940a751efe failed with status 1, stdout="", stderr="exit status 3\n"

This can be solved by adding the following lines to /etc/apparmor.d/local/usr.sbin.dnsmasq:

owner /run/user/[0-9]*/containers/cni/dnsname/*/dnsmasq.conf r,
owner /run/user/[0-9]*/containers/cni/dnsname/*/addnhosts r,
owner /run/user/[0-9]*/containers/cni/dnsname/*/pidfile rw,

And then reloading the AppArmor profile:

# apparmor_parser -R /etc/apparmor.d/usr.sbin.dnsmasq
# apparmor_parser /etc/apparmor.d/usr.sbin.dnsmasq

ルートレスモードでのコミット時にエラー

Error committing the finished image: error adding layer with blob "sha256:02823fca9b5444c196f1f406aa235213254af9909fca270f462e32793e2260d8": Error processing tar file(exit status 1) permitted operation

Check that the storage driver is overlay in the #Storage configuration.

Error building pause image after Podman upgrade 3.x to 4.0

Error: building local pause image: finding pause binary: exec: "catatonit": executable file not found in $PATH

Install the catatonit package to fix the error.

For details on upgrading from 3.x to 4.0, see the official blog article

Container dns will not be enabled

WARN[0000]  binary not found, container dns will not be enabled

If you installed netavark as podman network backend you need to install aardvark-dns

failed to move rootless netns

docker-compose up
ERRO[0000] failed to move the rootless netns slirp4netns process to the systemd user.slice: Process org.freedesktop.systemd1 exited with status 1

Can be solved by starting/enabling podman.service.

Permission denied: OCI permission denied

podman exec openvas_openvas_1 bash
Error: crun: writing file `/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/user.slice/libpod-b3e8048a9b91e43c214b4d850ac7132155a684d6502e12e22ceb6f73848d117a.scope/container/cgroup.procs`: Permission denied: OCI permission denied

Can be solved: https://bbs.archlinux.org/viewtopic.php?id=253966

env DBUS_SESSION_BUS_ADDRESS= podman ...
env DBUS_SESSION_BUS_ADDRESS= podman-compose ...

Add pause to process

WARN[0000] Failed to add pause process to systemd sandbox cgroup: Process org.freedesktop.systemd1 exited with status 1 

Can be solved using: https://github.com/containers/crun/issues/704

# echo +cpu +cpuset +io +memory +pids > /sys/fs/cgroup/cgroup.subtree_control

参照