美文网首页
RedHat/CentOS8【Podman】安装和配置

RedHat/CentOS8【Podman】安装和配置

作者: 张毅SOHO | 来源:发表于2021-01-07 10:36 被阅读0次

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

2)安装 Podman-Compose:

[root@host ~]# dnf install python3
# 当 Podman 版本  < 3.4 时,安装 0.1.x 版本
[root@host ~]# pip3 install podman-compose==0.1.11
# 当 Podman 版本  >= 3.4 时,安装 1.x 版本(最新版本)
[root@host ~]# pip3 install podman-compose

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

更新

[root@host ~]# dnf upgrade podman
# 当 Podman 版本  < 3.4 时,安装 0.1.x 版本
[root@host ~]# pip3 install -U podman-compose==0.1.11
# 当 Podman 版本  >= 3.4 时,安装 1.x 版本(最新版本)
[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 = "gms53j1g.mirror.aliyuncs.com"

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

1)创建镜像仓库目录:

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

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/storage"

5、修改 Pod 镜像。Podman 中引入了 Pod 对象,作为容器的名字空间,使用 Pod 对象需要启动一个管理工具容器,这个工具默认的镜像在国内无法下载,需要修改成国内提供下载的镜像名。

1)备份原配置文件:

[root@host ~]# cp /usr/share/containers/containers.conf /usr/share/containers/containers.conf.bak

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

[root@host ~]# vi /usr/share/containers/containers.conf

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

# 注释默认镜像配置
# infra_image = "k8s.gcr.io/pause:3.5"
# 修改为:
infra_image = "registry.access.redhat.com/ubi8/pause"

6、修改 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

7、创建指令别名。Podman 和 Docker 的指令相似度非常强,对于习惯使用 Docker 的用户可以通过指令别名来保持这个习惯。

1)在当前用户的主目录下使用文本编辑器打开配置文件:

[root@host ~]# vi ~/.bashrc

2)在文件中追加以下内容后保存:

alias podman="sudo podman"
alias docker="sudo podman"
alias podman-compose="sudo podman-compose"
alias docker-compose="sudo podman-compose"

3)立即应用这些配置:

[root@host ~]# source ~/.bashrc

相关文章

网友评论

      本文标题:RedHat/CentOS8【Podman】安装和配置

      本文链接:https://www.haomeiwen.com/subject/sxoaoktx.html