CentOS8にdockerをインストールする

だらだら書いたので、結論を先に書く。

  • container-toolsモジュールを無効にしてdocker公式手順を実行する
    無効にせず、containerd.ioだけRPMによるインストールでも可
  • RHEL8/CentOS8はdockerをサポートしておらず、代わりにpodmanを提供している
    この記事は最終的にpodmanをインストールしている

 

以下、経緯。

 

CentOS7のときはextraリポジトリにあったので、適当に入力したらインストールできた。

yum install docker

CentOS8にdockerはなかった。

http://ftp.jaist.ac.jp/pub/Linux/CentOS/7/extras/x86_64/Packages/

http://ftp.jaist.ac.jp/pub/Linux/CentOS/8/extras/x86_64/os/Packages/

なので公式からインストールする。

https://docs.docker.com/engine/install/centos/

dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

dnf install docker-ce docker-ce-cli containerd.io

しかしエラーが出てインストールできない。 containerd.ioが1.2.2-3以上が必要だが、除外されている。

エラー:
問題: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded

インストールできるバージョンを確認する。

# dnf list --showduplicates containerd.io
利用可能なパッケージ
containerd.io.x86_64 1.2.0-1.2.beta.2.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.0.rc.0.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.2.rc.2.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-3.el7 docker-ce-stable

ちなみに、CentOS7で実行すると、1.2.13-3.1.el7がインストールできる。CentOS8のどれかのリポジトリが邪魔してることを疑い、docker-ce-stableリポジトリのみ有効にすると、インストールできるバージョンとして表示される。

# dnf list --disablerepo=* --enablerepo=docker-ce-stable --showduplicates containerd.io
利用可能なパッケージ
containerd.io.x86_64 1.2.0-1.2.beta.2.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.0.rc.0.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.2.rc.2.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-3.el7 docker-ce-stable
containerd.io.x86_64 1.2.2-3.el7 docker-ce-stable
containerd.io.x86_64 1.2.2-3.3.el7 docker-ce-stable
containerd.io.x86_64 1.2.4-3.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.5-3.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.6-3.3.el7 docker-ce-stable
containerd.io.x86_64 1.2.10-3.2.el7 docker-ce-stable
containerd.io.x86_64 1.2.13-3.1.el7 docker-ce-stable

有効になっているリポジトリを確認して、どれがexcludedしているかひとつづつ確認する。犯人はAppStream。

# dnf repolist
repo id repo の名前 状態
AppStream CentOS-8 - AppStream 5,308
BaseOS CentOS-8 - Base 1,661
docker-ce-stable Docker CE Stable - x86_64 63
extras CentOS-8 - Extras 16 

AppStreamは8から現れたオプショナルなリポジトリで、パッケージをまとめたモジュールというものがある。このモジュールを確認してみる。

# dnf module list
CentOS-8 - AppStream
Name Stream Profiles Summary
389-ds 1.4 389 Directory Server (base)
ant 1.10 [d] common [d] Java build tool
container-tools rhel8 [d] common [d] Common tools and dependencies for container runtimes
container-tools 1.0 [x] common [d] Common tools and dependencies for container runtimes

以下略

 container-toolsというのが怪しいので無効にしてみる。

# dnf module disable container-tools
========================================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
========================================================================================================================
モジュールの無効化:
container-tools

トランザクションの概要
========================================================================================================================

これでよろしいですか? [y/N]: y
完了しました!
# dnf list --showduplicate containerd.io
利用可能なパッケージ
containerd.io.x86_64 1.2.0-1.2.beta.2.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.0.rc.0.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-2.2.rc.2.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.0-3.el7 docker-ce-stable
containerd.io.x86_64 1.2.2-3.el7 docker-ce-stable
containerd.io.x86_64 1.2.2-3.3.el7 docker-ce-stable
containerd.io.x86_64 1.2.4-3.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.5-3.1.el7 docker-ce-stable
containerd.io.x86_64 1.2.6-3.3.el7 docker-ce-stable
containerd.io.x86_64 1.2.10-3.2.el7 docker-ce-stable
containerd.io.x86_64 1.2.13-3.1.el7 docker-ce-stable

container-toolsの中身(パッケージ)はRHELのサイトで確認できる。ストリームはrhel8(dnf module list実行時に[d]が付いている方)。

https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/package_manifest/AppStream-repository

 

この中にpodman-dockerというものがある。RedHatが用意したdockerの代替品で、8からサポートしなくなった(extraリポジトリからなくした)のはこれのためらしい。

https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html-single/building_running_and_managing_containers/index

RedHatがこっちをサポートするというのであれば、こちらを入れてみる。

まずはもとの状態に戻す。

dnf module enable container-tools

dnf config-manager --disable docker-ce-stable

 どうでも良いけど、dnf config-manager --disableを実行したら、repoファイル内の空白行が全部消えるので、嫌な人はファイルを直接編集する。あるいはファイルを削除する。

 

RedHatのドキュメントの通り、まずcontainer-toolsモジュールをインストールする。

# dnf module install container-tools
エラー:
問題: conflicting requests
- nothing provides python3-psutil needed by python-podman-api-1.2.0-0.2.gitd0a45fe.module_el8.1.0+298+41f9343a.noarch
(インストール不可のパッケージをスキップするには、'--skip-broken' を追加してみてください または、'--nobest' を追加して、 最適候補のパッケージのみを使用しないでください)

python3-psutilがないといわれる。今度はexcludedではなく実物がないらしい。

RHEL8のpython38モジュールに含まれるそうだが、(確認した時点で)CentOS8ではpython27, python36モジュールしかなかったので、別のところから取得する。CentOS8はepelリポジトリから取得する(extraリポジトリインストーラがある)。

https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/package_manifest/AppStream-repository

 

# dnf install epel-release

# dnf module install container-tools
========================================================================================================================
パッケージ Arch バージョン リポジトリー サイズ
========================================================================================================================
アップグレード:
audit x86_64 3.0-0.13.20190507gitf58ec40.el8 BaseOS 252 k
audit-libs x86_64 3.0-0.13.20190507gitf58ec40.el8 BaseOS 116 k
policycoreutils x86_64 2.9-3.el8_1.1 BaseOS 377 k
group/moduleパッケージをインストール:
buildah x86_64 1.11.6-6.module_el8.1.0+298+41f9343a AppStream 8.5 M
cockpit-podman noarch 11-1.module_el8.1.0+298+41f9343a AppStream 1.0 M
conmon x86_64 2:2.0.6-1.module_el8.1.0+298+41f9343a AppStream 37 k
container-selinux noarch 2:2.124.0-1.module_el8.1.0+298+41f9343a AppStream 47 k
containernetworking-plugins x86_64 0.8.3-4.module_el8.1.0+298+41f9343a AppStream 20 M
fuse-overlayfs x86_64 0.7.2-5.module_el8.1.0+298+41f9343a AppStream 60 k
podman x86_64 1.6.4-4.module_el8.1.0+298+41f9343a AppStream 12 M
python-podman-api noarch 1.2.0-0.2.gitd0a45fe.module_el8.1.0+298+41f9343a AppStream 43 k
runc x86_64 1.0.0-64.rc9.module_el8.1.0+298+41f9343a AppStream 2.6 M
skopeo x86_64 1:0.1.40-8.module_el8.1.0+298+41f9343a AppStream 5.8 M
slirp4netns x86_64 0.4.2-3.git21fdece.module_el8.1.0+298+41f9343a AppStream 88 k
toolbox x86_64 0.0.4-1.module_el8.1.0+293+ad8ef41f AppStream 15 k
udica noarch 0.2.1-2.module_el8.1.0+298+41f9343a AppStream 48 k
依存関係のインストール:
containers-common x86_64 1:0.1.40-8.module_el8.1.0+298+41f9343a AppStream 49 k
criu x86_64 3.12-9.el8 AppStream 482 k
libnet x86_64 1.1.6-15.el8 AppStream 67 k
ostree-libs x86_64 2019.2-1.el8 AppStream 391 k
podman-manpages noarch 1.6.4-4.module_el8.1.0+298+41f9343a AppStream 176 k
protobuf-c x86_64 1.3.0-4.el8 AppStream 37 k
python3-cairo x86_64 1.16.3-6.el8 AppStream 90 k
python3-gobject x86_64 3.28.3-1.el8 AppStream 25 k
python3-pip noarch 9.0.3-15.el8 AppStream 19 k
python3-systemd x86_64 234-8.el8 AppStream 81 k
python36 x86_64 3.6.8-2.module_el8.1.0+245+c39af44f AppStream 19 k
setroubleshoot-plugins noarch 3.3.10-3.el8 AppStream 366 k
checkpolicy x86_64 2.9-1.el8 BaseOS 348 k
cockpit-bridge x86_64 196.3-1.el8 BaseOS 606 k
cockpit-system noarch 196.3-1.el8 BaseOS 1.6 M
fuse3-libs x86_64 3.2.1-12.el8 BaseOS 94 k
libvarlink x86_64 18-3.el8 BaseOS 44 k
policycoreutils-python-utils noarch 2.9-3.el8_1.1 BaseOS 250 k
python3-audit x86_64 3.0-0.13.20190507gitf58ec40.el8 BaseOS 85 k
python3-libsemanage x86_64 2.9-1.el8 BaseOS 127 k
python3-policycoreutils noarch 2.9-3.el8_1.1 BaseOS 2.2 M
python3-setools x86_64 4.2.2-1.el8 BaseOS 600 k
python3-setuptools noarch 39.2.0-5.el8 BaseOS 162 k
python3-psutil x86_64 5.6.3-5.el8 epel 396 k
弱い依存関係のインストール:
setroubleshoot-server x86_64 3.3.20-2.el8 AppStream 397 k
モジュールプロファイルのインストール:
container-tools/common
モジュールストリームの有効化:
python36 3.6

 メインのpodmanをインストールする。

# dnf install podman-docker
========================================================================================================================
パッケージ アーキテクチャー バージョン リポジトリー サイズ
========================================================================================================================
インストール:
podman-docker noarch 1.6.4-4.module_el8.1.0+298+41f9343a AppStream 35 k

トランザクションの概要
========================================================================================================================

 

動作確認:参考 https://tech-lab.sios.jp/archives/16269

# podman run docker.io/hello-world:latest

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/

 

# podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fcf4a6a6b136 docker.io/library/hello-world:latest /hello 8 minutes ago Exited (0) 8 minutes ago serene_cori

 

# podman rm serene_cori
fcf4a6a6b136f2294b438a9c811dd3f6c8ec077d5e654ea33270d5b2cd274d35

 

# docker images
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/library/hello-world latest bf756fb1ae65 4 months ago 20 kB

 

# docker rmi bf756fb1ae65
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Untagged: docker.io/library/hello-world:latest
Deleted: bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b

podmanをインストールするとdockerコマンドが使えるようになるが、内部でpodmanコマンドを実行している(シンボリックリンクではない)。

# cat /usr/bin/docker
#!/bin/sh
[ -f /etc/containers/nodocker ] || \
echo "Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg." >&2
exec /usr/bin/podman "$@"