Fedora 31 などでCGroup V2 (unified CGroup 階層) がデフォルトになっているので、そういうLinuxホストでpodman を用いて動かす話です。手順としてはUbuntu/Debian向けに書いてあります。fedora 31なら dnf install fuse-overlayfs slirp4netns をrootで実行してから dnf install buildah skopeo podman をrootで実行し、一般ユーザーでpodman info を実行すれば問題なく一般ユーザーで使えるようになります。Ubuntu Disco 以降およびDebian Bullseyeなら非ルートユーザーによるrootlessコンテナが使えます。Ubuntu Eoan と Fedora 31 でtensorflowのドッカーイメージを問題なく実行できています(下記参照)
crun, slirp4netns, fuse-overlayfs, containernetworking-plugins のインストール
Ubuntu の場合
deb http://jp.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
APT::Default-Release "現在使用中のリリース(eoanなど)";
を設定してから apt-get update, apt-get -t focal install crun fuse-overlayfs slirp4netns containernetworking-plugins する
Debian の場合
deb http://deb.debian.org/debian testing main contrib non-free
APT::Default-Release "現在使用中のリリース(busterなど)";
を設定してから apt-get update, apt-get -t testing install crun fuse-overlayfs slirp4netns containernetworking-plugins する
Project Atomic のAPTソースの設定
Ubuntuの場合(rootで)
apt-get install software-properties-common
add-apt-repository ppa:projectatomic/ppa
とすると /etc/apt/sources.list.d/projectatomic-ubuntu-ppa-eoan.list が出来るので、それをエディタで開いてリリース名(eoanなど)をdiscoかbionicに変える。これは上記PPAがbionicとdiscoのパッケージしか用意していないからである。
Debianの場合(rootで)
deb [ allow-insecure=yes ] http://ppa.launchpad.net/projectatomic/ppa/ubuntu disco main
を追加。
Project Atomicからパッケージインストール (Ubuntu&Debian共通)
apt-get -t disco install buildah podman skopeo (discoは前項のリリース名と同じにすること)
設定ファイルの変更
-
https://github.com/projectatomic/registries/blob/master/registries.fedora の内容を
/etc/containers/registries.confにコピーする -
/usr/share/containers/libpod.confの中のruntime = "runc"の等号の右辺を"crun"に変更し保存する
上記の作業で docker ナントカのかわりにpodman なんとか と打てば同じことができる(ただしsudoではなくてrootログインが必要かも知れない)。
一般ユーザーでのrootlessコンテナの使用 (Linux カーネル4.18以降が必要)
-
podman infoを実行し設定ファイルを作る -
~/.config/containers/libpod.confのruntimeの項目をcrunにする -
~/.config/containers/storage.confのdriverの項目をoverlayにし、mount_programの項目を"/usr/bin/fuse-overlayfs"
とする。
tensorflowの実行
上記の設定のあとに一般ユーザーで podman run -it --rm tensorflow/tensorflow:1.15.0-py3 python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))" を一般ユーザーで問題なく実行できた。
トラブルシューティング
Error processing tar file(exit status 1): there might not be enough IDs available in the namespace (requested 0:42 for /etc/gshadow): lchown /etc/gshadow: invalid argument
というエラーが一般ユーザーで出たら
-
/etc/subuid,/etc/subgidに自分のログインID:100000:65536のような行が存在するか確認し、なければ追加する。 -
~/.config/containers/storage.confのignore_chown_errors =の右辺を"true"にする。 - それで
podman run -it ubuntu bashがエラー無く実行できてドッカーコンテナ内のルートプロンプトが出ることを確認する。
podman-compose
docker-compose に対応するコマンドは上記の作業ではインストールされない。それでは困る場合 pip3 install -U podman-compose を用いてpodman-composeコマンドをインストールする。CGroup V2なUbuntu Eoan上でLaTeXで年賀状を作る に示されたdockerコンテナを podman-composeで動かし年賀状を作成することができた。