在CentOS上使用Podman

本文主要介绍如何在CentOS上使用podman,主要步骤参见这篇文章:https://www.linuxtechi.com/run-containers-podman-centos-8-rhel-8/

一,安装

尽量使用dnf,不要使用yum,可以用yum安装dnf

1.1 更新系统

sudo dnf makecache
sudo dnf upgrade
sudo dnf update

1.2 安装podman

sudo dnf -y install 'dnf-command(copr)'
sudo dnf -y install podman

1.3 查看安装

podman --verion

你应该看到如下内容:

1
podman version 1.6.4

1.4 rootless问题

非root权限的podman,将需要设置max_user_namespaces

sudo sysctl user.max_user_namespaces=15000

二,修改为国内源:

在如下目录:

sudo vim /etc/containers/registries.conf

将阿里云的镜像放在最前面,将docker.io放在第二个

1
2
3
4
5
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
location = "******.mirror.aliyuncs.com"

xxx需要你登录阿里云,搜索“容器镜像”,在控制台里选择“镜像加速器”,得到完整的地址

三,容器权限问题:

进入容器时,指定user为root用户,-u 0,例如,一般进入容器的命令为:

podman exec -it xxxxx bash

这里修改为:

podman exec -it -u 0 xxxxx bash

四,数据持久化问题:

一般数据是随着容器的生命周期进行变动的,如果容器移除,对应的数据也被删除了,例如nginx的配置,nexus的仓库数据等。所以一般会指定宿主机的目录给容器挂载使用。

有两种方式:

  1. 容器自带的volume技术
  2. 指定文件夹给容器挂载

文件夹挂载的方式涉及到文件夹的读写权限问题,volume则不存在这个问题。

volume的使用

1
2
3
4
podman volume ls        #查看所有卷
podman volume create xxxx #创建名为`xxxx`的卷
podman volume rm xxxx #移除
podman volume inspect xxxx #检查这个卷