banner
云野阁

云野阁

闲云野鹤,八方逍遥

podman-5.1.2 部署

基礎環境

系統:openEuler 22.03 (LTS-SP4) X86

軟體:podman-5.1.2、podman-compose-1.2.0

配置 yum 源#

echo '[baseos]
name=CentOS-Stream-9-Base-mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/BaseOS/x86_64/os/
gpgcheck=0

[appstream]
name=CentOS-Stream-9-Appstream-mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-stream/9-stream/AppStream/x86_64/os/
gpgcheck=0' > /etc/yum.repos.d/CentOS.repo

安裝 podman 和 podman-compose#

# 安裝podman podman-docker
yum install -y podman podman-docker
# 下載podman-compose
pip install podman-compose
# 創建文件,使用docker命令時不報錯
touch /etc/containers/nodocker

安裝podman-docker後可使用 docker 命令

啟動並查看版本#

# 啟動podman
systemctl start podman
# 設置開機自啟
systemctl enable podman
# 查看版本
podman --version

永久啟用 cgroups-v2#

📚海拾🐚 cgroups-v2 cgroup v2 for containers 需要內核版本 4.15 或更高,而建議在 5.2 或更高再使用 cgroup v2。
podman安裝完成後,直接使用podman命令時,會出現以下提示,大致意思是說cgroups-v1已被棄用,要設置環境變數`PODMAN_IGNORE_CGROUPSV1_WARNING`,以啟用 cgroups-v2。

WARN[0000] Using cgroups-v1 which is deprecated in favor of cgroups-v2 with Podman v5 and will be removed in a future version. Set environment variable PODMAN_IGNORE_CGROUPSV1_WARNING to hide this warning.

(1)確定系統是否支持 cgroups-v2

grep cgroup /proc/filesystems

如果系統支持會顯示以下內容:

nodev cgroup
nodev cgroup2

(2)輸入ls /sys/fs/cgroup/cgroup.controllers檢查是否已經激活 cgroups-v2,如果顯示ls: cannot access '/sys/fs/cgroup/cgroup.controllers': No such file or directory,則表示還未激活。

(3)永久激活 cgroups-v2

打開 GRUB 配置文件/etc/default/grub,修改內核命令行參數。在GRUB_CMDLINE_LINUX所在行加入以下參數:

systemd.unified_cgroup_hierarchy=1

GRUB_CMDLINE_LINUX="resume=/dev/mapper/openeuler-swap rd.lvm.lv=openeuler/root rd.lvm.lv=openeuler/swap cgroup_disable=files apparmor=0 crashkernel=512M systemd.unified_cgroup_hierarchy=1"

(4)更新 GRUB 配置,重啟系統使更改的參數生效。

# 更新GRUB配置
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
# 重啟
reboot

驗證 cgroups-v2#

重啟系統後,輸入命令查看 podman 的 cgroupVersion 的版本,顯示版本為 v2,則啟用成功。並且在輸入 podman 命令時,不會在有提示。

podman info | grep cgroupVersion

cgroupVersion: v2

配置鏡像源#

打開配置文件/etc/containers/registries.conf,配置國內鏡像源,加速拉取鏡像。

echo 'unqualified-search-registries = ["docker.io"]
[[registry]]
prefix = "docker.io"
location = "dockerhub.icu"
insecure = true
[[registry.mirror]]
location = "ghcr.geekery.cn"
insecure = true
[[registry.mirror]]
location = "hub.rat.dev"
insecure = true
[[registry.mirror]]
location = "docker.wanpeng.top"
insecure = true
[[registry.mirror]]
location = "f1361db2.m.daocloud.io"
insecure = true' >> /etc/containers/registries.conf

拉取鏡像測試#

podman run hello-world

成功拉取並運行後會顯示以下效果:

Resolved "hello-world" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull quay.io/podman/hello...
Getting image source signatures
Copying blob 81df7ff16254 done |
Copying config 5dd467fce5 done |
Writing manifest to image destination
!... Hello Podman World ...!

     .--"--.
   / -     - \
  / (O)   (O) \
 .---. /`  \   |~~
~/  o  o \~~~~.----. ~~
| =(X)= |~  / (O (O) \
~~~~~~~  ~| =(Y_)=-  |
~~~~    ~~~|   U      |~~

Project:   https://github.com/containers/podman
Website:   https://podman.io
Desktop:   https://podman-desktop.io
Documents: https://docs.podman.io
YouTube:   https://youtube.com/@Podman
X/Twitter: @Podman_io
Mastodon:  @[email protected]

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。