欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

快速上手 Red Hat/CentOS 8 中的 Podman 安装与设置指南

最编程 2024-07-19 16:08:49
...

Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用,在 RedHat/CentOS8 版本已默认安装。Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供与 Docker 非常相似的功能,并且使用与 Docker 兼容的命令行前端来管理镜像。

Podman 和 Docker 的使用方法几乎完全一致。其中 podman 指令对应 docker 指令,podman-compose 指令对应 docker-compose 指令。

Podman 支持使用非 root 用户创建和管理容器,但是部分功能(如:目录挂载和宿主机磁盘挂载)会出现用户权限引起的问题,因此特别推荐使用 root 权限创建和管理容器。

关于 Docker 和 Docker-Compose 的使用方法请阅读文章《RedHat/CentOS8【Docker】镜像制作编排和容器部署》,文章地址【https://www.jianshu.com/p/a4198b127729】。


1、安装 Podman 和 Podman-Compose。

1)安装 Podman:

[root@host ~]# dnf install podman podman-plugins cockpit cockpit-podman
[root@host ~]# systemctl enable --now podman
[root@host ~]# systemctl enable --now cockpit.socket

安装cockpit和cockpit-podman后,可以通过【https://ip:9090】来管理容器。

2)安装 Podman-Compose:

[root@host ~]# dnf install python3
[root@host ~]# pip3 install podman-compose

程序安装位置:
镜像管理程序:/usr/bin/podman
编译文件执行程序:/usr/local/bin/podman-compose
配置文件目录:/etc/containers,/usr/share/containers

更新

[root@host ~]# dnf upgrade podman
[root@host ~]# pip3 install -U podman-compose

2、设置国内镜像仓库加速器。

1)备份原配置文件:

[root@host ~]# cp /etc/containers/registries.conf /etc/containers/registries.conf.bak

2)使用文本编辑器打开配置文件:

[root@host ~]# vi /etc/containers/registries.conf

3)删除原有内容,重新编写文件内容后保存:

unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "docker.io"

[[registry.mirror]]
location = "mirror.baidubce.com"

[[registry.mirror]]
location = "gms53j1g.mirror.aliyuncs.com"

4、设置镜像仓库和运行时目录。

1)创建镜像仓库目录:

[root@host ~]# mkdir -p /data/containers/{run,graph}

2)备份原配置文件:

[root@host ~]# cp /etc/containers/storage.conf /etc/containers/storage.conf.bak

3)使用文本编辑器打开配置文件:

[root@host ~]# vi /etc/containers/storage.conf

4)修改文件以下内容后保存:

# root 用户运行时目录
runroot = "/data/containers/run"
# root 用户镜像仓库目录
graphroot = "/data/containers/graph"

5、修改 SELinux 配置文件,永久关闭 SELinux。

使用文本编辑器打开"/etc/selinux/config"文件:

[root@host ~]# vi /etc/selinux/config

将 "SELINUX" 参数设置为:"permissive" 或者 "disabled",并保存:

#     enforcing - 表示启用 SELinux 安全策略。
#     permissive - 表示启用 SELinux 安全策略,但不强制验证。如果执行第一步可以正常运行,则建议设置此值。
#     disabled - 关闭 SELinux 安全策略,相当于没有安装 SELinux。
SELINUX=disabled

重启服务器:

[root@host ~]# reboot