WSL2下 Debian10 运行Podman

WSL2下  Debian10 运行Podman

在 WSL2 的 Debian 10 上安装并运行 Podman。Debian 10 自带源里没有 Podman,要先加 openSUSE 的 Kubic 仓库;装好后还会遇到依赖和 journald、cgroup 报错,下面按顺序解决。

安装 Podman

将 OS 相关变量加载到 shell:

. /etc/os-release

添加 repo:

sudo sh -c "echo 'deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"

添加 apt key:

curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_${VERSION_ID}/Release.key | sudo apt-key add -

安装前常规更新:

sudo apt update

安装 Podman:

sudo apt install podman

解决依赖报错

安装时提示依赖不满足

The following packages have unmet dependencies:podman : Depends: libseccomp2 (>= 2.4.3-1) but 2.3.3-4 is to be installedDepends: dbus-user-session but it is not going to be installedRecommends: slirp4netns (>= 100:1.1.8-3) but it is not going to be installedRecommends: containernetworking-plugins (>= 100:0.9.1-1) but it is not going to be installedRecommends: uidmap but it is not going to be installedRecommends: fuse-overlayfs but it is not going to be installedE: Unable to correct problems, you have held broken packages.

按提示逐一安装缺失的依赖

apt-get install libseccomp2 dbus-user-session slirp4netns containernetworking-plugins uidmap fuse-overlayfs

其中libseccomp2 可能需要添加源:

deb http://ftp.de.debian.org/debian sid maindeb http://mirrors.aliyun.com/debian sid main

修复 journald 报错

验证 Podman 是否安装成功

podman info

运行 podman info 可能会报错

ERRO[0000] unable to write system event: "write unixgram @00008->/run/systemd/journal/socket: sendmsg: no such file or directory"

编辑 /etc/containers/containers.conf

sudo vim /etc/containers/containers.conf

把 events_logger 从 journald 改为 file

原来是:

events_logger = "journald"

改为(新建文件请直接添加):

events_logger = "file"

测试运行

运行一个 nginx 容器测试

podman run --name nginx -p 8080:80 -d nginx:alpine

拉取镜像时可能报错

Trying to pull docker.io/library/nginx:alpine...Getting image source signaturesCopying blob 758848c48411 doneCopying blob 0ae30075c5da doneCopying blob 9da81141e74e done[engine]Copying blob 540db60ca938 doneCopying blob 7f40e809fb2d doneCopying blob b2e41dd2ded0 doneCopying config a6eb2a334a doneWriting manifest to image destinationStoring signaturesERRO[0032] unable to write pod event: "write unixgram @0000e->/run/systemd/journal/socket: sendmsg: no such file or directory"WARN[0032] Failed to add conmon to systemd sandbox cgroup: dial unix /run/systemd/private: connect: no such file or directoryError: cannot open sd-bus: No such file or directory: OCI not found

再次修改 containers.conf

vim /etc/containers/containers.conf

添加 cgroup_manager 配置

[engine]events_logger="file"cgroup_manager="cgroupfs"

再次尝试运行nginx:alpine,并打开 http://localhost:8080/ ,看到熟悉的Welcome to nginx! 就完工啦。

小结

WSL2 里没有 systemd,所以 Podman 的 events_logger 要改成 file、cgroup_manager 改成 cgroupfs,否则会报 journald 和 cgroup 相关错误。改完后再跑一次 nginx 容器,能打开欢迎页就说明跑通了。

更多安装请参照:

留下评论