2021/09/16

Just a Note: Install Podman in WSL2

當初是因為 docker desktop 要開始收費,所以進行了很初期的 survey,不管是 docker 還是 podman,基本上在 windows 上不外乎就是透過 virtualbox/wsl 載入能執行 docker/podman 的 linux 系統,對於不熟 linux 的人(像我),程序難免複雜。
而這一年來,使用過 rancher-desktop、podman、minikube,在 windows 上的發展也都相當健全,我認為也都很容易便可當作 windows 上容器化技術的開發工具,不需要像初期一樣大費周章了。
rancher-desktop:https://rancherdesktop.io/
podman:https://podman.io/
minikube:https://minikube.sigs.k8s.io/

rancher-desktop、podman 會使用 wsl,minikube 則可以選擇 virtualbox 或 hyper-v 作為 hypervisor,有點像早期的 docker-toolbox。
我個人比較偏好使用 wsl 的 rancher-desktop、podman,主要是因為當要使用 container volumn 時,多透過一層 hypervisor 在設定上比較繁瑣,先前用 virtualbox 時,這部分常踩到雷。
rancher-desktop 可選擇 containerd 或 docker 作為 container runtime,對於原本習慣用 docker 的人應該會比較熟悉,在家試一些新東西時,主要都是使用 rancher-desktop;
podman 初期接觸的契機是因為工作,Red Hat 在 OpenShift 上主推的 container runtime 就是 podman,後來也因為 k8s 對於 docker 的支援上存在一些爭議與討論,所以工作上主要就都改用 podman,雖然還是只用在類比 docker command 上就是了。現在新的版本已經直接支援 docker api (模擬),也就是說安裝了 podman for windows 後,可以直接使用 docker 指令,但畢竟不是原生 docker,應該還是會有一些出入吧;
至於 minikube,是公司的分享會介紹的,只有簡單使用過,但因為會產生 virtualbox 或 hyper-v 的 vm,有些資安議題上的爭議,再加上前面提到的 volume 議題,所以我個人就不太偏好了,不過畢竟是公司在推廣的工具,所以還是加減看看。

近幾年容器化技術發展快速,無論使用哪套工具,在 windows 上皆已相當方便,原本複雜程序的文字就還是留著作為歷史紀錄吧!

2022.09.10 中秋


Reference:
1. https://medium.com/%E6%B5%A6%E5%B3%B6%E5%A4%AA%E9%83%8E%E7%9A%84%E6%B0%B4%E6%97%8F%E7%BC%B8/wsl-docker-virtual-box-on-hyper-v-ca77deebcf86
2. https://www.redhat.com/sysadmin/podman-windows-wsl2
3. https://github.com/containers/podman/issues/6162
4. https://github.com/MicrosoftDocs/WSL/issues/412#issuecomment-828924500

Note1: 根據上述 1,安裝 WSL2 和 Ubuntu 18.04 LTS。
Note1: Install WSL2 & Ubuntu 18.04 LTS (link 1)

Note2: 根據上述 3,podman 某個版本後,上述 2 中的 libpod.conf 已被換成 containers.conf。
Note2: Base to link 3, libpod.conf in link 2. should be replaced with containers.conf after certain podman version.

Note3: 根據上述 4,把 wsl 的實體檔案搬到別的磁碟
Note3: Base on link 4, move wsl vhdx file to other disk

Process

lancelot@Homeserver:/$ . /etc/os-release

lancelot@Homeserver:/$ sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/x${NAME}_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"

lancelot@Homeserver:/$ cd ~

lancelot@Homeserver:~$ wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/x${NAME}_${VERSION_ID}/Release.key -O Release.key
2021-09-15 22:37:54 URL:https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_18.04/Release.key [1093/1093] -> "Release.key" [1]

lancelot@Homeserver:~$ sudo apt-key add - < Release.key
OK

lancelot@Homeserver:~$ sudo apt-get update -qq

lancelot@Homeserver:~$ sudo apt-get -qq -y install podman
(Reading database ... 28579 files and directories currently installed.)
Preparing to unpack .../libseccomp2_2.5.1-1ubuntu1~18.04.1_amd64.deb ...
Unpacking libseccomp2:amd64 (2.5.1-1ubuntu1~18.04.1) over (2.3.1-2.1ubuntu4) ...
Setting up libseccomp2:amd64 (2.5.1-1ubuntu1~18.04.1) ...
(Reading database ... 28579 files and directories currently installed.)
Preparing to unpack .../00-dbus_1.12.2-1ubuntu1.2_amd64.deb ...
Unpacking dbus (1.12.2-1ubuntu1.2) over (1.12.2-1ubuntu1) ...
Preparing to unpack .../01-libdbus-1-3_1.12.2-1ubuntu1.2_amd64.deb ...
Unpacking libdbus-1-3:amd64 (1.12.2-1ubuntu1.2) over (1.12.2-1ubuntu1) ...
Selecting previously unselected package catatonit.
Preparing to unpack .../02-catatonit_0.1.5~1_amd64.deb ...
Unpacking catatonit (0.1.5~1) ...
Selecting previously unselected package conmon.
Preparing to unpack .../03-conmon_100%3a2.0.27-1_amd64.deb ...
Unpacking conmon (100:2.0.27-1) ...
Selecting previously unselected package containers-common.
Preparing to unpack .../04-containers-common_100%3a1-21_all.deb ...
Unpacking containers-common (100:1-21) ...
Selecting previously unselected package libprotobuf10:amd64.
Preparing to unpack .../05-libprotobuf10_3.0.0-9.1ubuntu1_amd64.deb ...
Unpacking libprotobuf10:amd64 (3.0.0-9.1ubuntu1) ...
Selecting previously unselected package python3-protobuf.
Preparing to unpack .../06-python3-protobuf_3.0.0-9.1ubuntu1_amd64.deb ...
Unpacking python3-protobuf (3.0.0-9.1ubuntu1) ...
Selecting previously unselected package libnet1:amd64.
Preparing to unpack .../07-libnet1_1.1.6+dfsg-3.1_amd64.deb ...
Unpacking libnet1:amd64 (1.1.6+dfsg-3.1) ...
Selecting previously unselected package libnl-3-200:amd64.
Preparing to unpack .../08-libnl-3-200_3.2.29-0ubuntu3_amd64.deb ...
Unpacking libnl-3-200:amd64 (3.2.29-0ubuntu3) ...
Selecting previously unselected package libprotobuf-c1:amd64.
Preparing to unpack .../09-libprotobuf-c1_1.2.1-2_amd64.deb ...
Unpacking libprotobuf-c1:amd64 (1.2.1-2) ...
Selecting previously unselected package criu.
Preparing to unpack .../10-criu_3.15-1_amd64.deb ...
Unpacking criu (3.15-1) ...
Selecting previously unselected package libyajl2:amd64.
Preparing to unpack .../11-libyajl2_2.1.0-2build1_amd64.deb ...
Unpacking libyajl2:amd64 (2.1.0-2build1) ...
Selecting previously unselected package crun.
Preparing to unpack .../12-crun_100%3a0.18-2_amd64.deb ...
Unpacking crun (100:0.18-2) ...
Selecting previously unselected package dbus-user-session.
Preparing to unpack .../13-dbus-user-session_1.12.2-1ubuntu1.2_amd64.deb ...
Unpacking dbus-user-session (1.12.2-1ubuntu1.2) ...
Selecting previously unselected package libgpgme11:amd64.
Preparing to unpack .../14-libgpgme11_1.10.0-1ubuntu2_amd64.deb ...
Unpacking libgpgme11:amd64 (1.10.0-1ubuntu2) ...
Selecting previously unselected package podman-plugins.
Preparing to unpack .../15-podman-plugins_100%3a1.1.1-5_amd64.deb ...
Unpacking podman-plugins (100:1.1.1-5) ...
Selecting previously unselected package podman.
Preparing to unpack .../16-podman_100%3a3.0.1-2_amd64.deb ...
Unpacking podman (100:3.0.1-2) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../17-slirp4netns_100%3a1.1.8-3_amd64.deb ...
Unpacking slirp4netns (100:1.1.8-3) ...
Selecting previously unselected package containernetworking-plugins.
Preparing to unpack .../18-containernetworking-plugins_100%3a0.9.1-1_amd64.deb ...
Unpacking containernetworking-plugins (100:0.9.1-1) ...
Setting up libnet1:amd64 (1.1.6+dfsg-3.1) ...
Setting up catatonit (0.1.5~1) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up slirp4netns (100:1.1.8-3) ...
Setting up libprotobuf-c1:amd64 (1.2.1-2) ...
Setting up libgpgme11:amd64 (1.10.0-1ubuntu2) ...
Setting up libprotobuf10:amd64 (3.0.0-9.1ubuntu1) ...
Setting up libyajl2:amd64 (2.1.0-2build1) ...
Setting up python3-protobuf (3.0.0-9.1ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up libnl-3-200:amd64 (3.2.29-0ubuntu3) ...
Setting up conmon (100:2.0.27-1) ...
Setting up containers-common (100:1-21) ...
Setting up containernetworking-plugins (100:0.9.1-1) ...
Setting up libdbus-1-3:amd64 (1.12.2-1ubuntu1.2) ...
Setting up podman-plugins (100:1.1.1-5) ...
Setting up criu (3.15-1) ...
Setting up crun (100:0.18-2) ...
Setting up dbus (1.12.2-1ubuntu1.2) ...
Setting up dbus-user-session (1.12.2-1ubuntu1.2) ...
Setting up podman (100:3.0.1-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...

lancelot@Homeserver:~$ sudo mkdir -p /etc/containers

lancelot@Homeserver:~$ echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf
[registries.search]
registries = ['docker.io', 'quay.io']

lancelot@Homeserver:~$ podman ps
ERRO[0000] unable to write system event: "write unixgram @00002->/run/systemd/journal/socket: sendmsg: no such file or directory"
CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES

lancelot@Homeserver:~$ sudo podman ps
ERRO[0000] unable to write system event: "write unixgram @00003->/run/systemd/journal/socket: sendmsg: no such file or directory"
CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES

lancelot@Homeserver:/mnt/c/Users/Lancelot$ sudo cp /usr/share/containers/containers.conf /etc/containers
[sudo] password for lancelot:

lancelot@Homeserver:/mnt/c/Users/Lancelot$ sudo vi /etc/containers/containers.conf
(base on link 2, uncomment & change the value of cgroup_manager to 'cgroupfs' and the value of events_logger to 'file')

lancelot@Homeserver:/mnt/c/Users/Lancelot$ podman ps
CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES

lancelot@Homeserver:/mnt/c/Users/Lancelot$ sudo podman ps
CONTAINER ID  IMAGE   COMMAND  CREATED  STATUS  PORTS   NAMES

沒有留言:

張貼留言