Podman使用

陆卓
2023-12-01

什么是Podman?

Podman 是一个开源的容器运行时项目,可在大多数 Linux 平台上使用。Podman 提供与 Docker 非常相似的功能。正如前面提到的那样,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。

Podman 可以管理和运行任何符合 OCI(Open Container Initiative)规范的容器和容器镜像。Podman 提供了一个与 Docker 兼容的命令行前端来管理 Docker 镜像。

Podman 官网地址:https://podman.io/

Podman和Docker的主要区别是什么?

  • dockers在实现CRI的时候,它需要一个守护进程,其次需要以root运行,因此这也带来了安全隐患。

  • podman不需要守护程序,也不需要root用户运行,从逻辑架构上,比docker更加合理。

  • 在docker的运行体系中,需要多个daemon才能调用到OCI的实现RunC。

  • 在容器管理的链路中,Docker Engine的实现就是dockerd

  • daemon,它在linux中需要以root运行,dockerd调用containerd,containerd调用containerd-shim,然后才能调用runC。顾名思义shim起的作用也就是“垫片”,避免父进程退出影响容器的运行

  • podman直接调用OCI,runtime(runC),通过common作为容器进程的管理工具,但不需要dockerd这种以root身份运行的守护进程。

  • 在podman体系中,有个称之为common的守护进程,其运行路径通常是/usr/libexec/podman/conmon,它是各个容器进程的父进程,每个容器各有一个,common的父则通常是1号进程。podman中的common其实相当于docker体系中的containerd-shim。

  • Podman的使用与docker有什么区别?

    podman的定位也是与docker兼容,因此在使用上面尽量靠近docker。在使用方面,可以分成两个方面来说,一是系统构建者的角度,二是使用者的角度。

    在系统构建者方面,用podman的默认软件,与docker的区别不大,只是在进程模型、进程关系方面有所区别。如果习惯了docker几个关联进程的调试方法,在podman中则需要适应。可以通过pstree命令查看进程的树状结构。总体来看,podman比docker要简单。由于podman比docker少了一层daemon,因此重启的机制也就不同了。

    在使用者方面,podman与docker的命令基本兼容,都包括容器运行时(run/start/kill/ps/inspect),本地镜像(images/rmi/build)、镜像仓库(login/pull/push)等几个方面。因此podman的命令行工具与docker类似,比如构建镜像、启停容器等。甚至可以通过alias

    docker=podman可以进行替换。因此,即便使用了podman,仍然可以使用http://docker.io作为镜像仓库,这也是兼容性最关键的部分。

    安装podman

    配置本地源

    [root@localhost ~]#  mount /dev/cdrom /mnt/    //挂载
    mount: /mnt: WARNING: device write-protected, mounted read-only.
    [root@localhost ~]# df -h
    Filesystem             Size  Used Avail Use% Mounted on
    devtmpfs               877M     0  877M   0% /dev
    tmpfs                  896M     0  896M   0% /dev/shm
    tmpfs                  896M  8.7M  887M   1% /run
    tmpfs                  896M     0  896M   0% /sys/fs/cgroup
    /dev/mapper/rhel-root   17G  1.7G   16G  10% /
    /dev/sda1             1014M  212M  803M  21% /boot
    tmpfs                  180M     0  180M   0% /run/user/0
    /dev/sr0                11G   11G     0 100% /mnt
    [root@localhost ~]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# ls
    redhat.repo
    [root@localhost yum.repos.d]# vi yyqx.repo
    [root@localhost yum.repos.d]# cat yyqx.repo
    [BaseOS]
    name=baseos
    baseurl=file:///mnt/BaseOS
    gpgcheck=0
    enabled=1
    [AppStream]
    name=appstream
    baseurl=file:///mnt/AppStream
    gpgcheck=0
    enabled=1
    [root@localhost yum.repos.d]# dnf clean all
    
    

    安装podman

    [root@localhost ~]# dnf list all|grep podman
    cockpit-podman.noarch                                  33-1.module+el8.5.0+12582+56d94c81                     AppStream 
    pcp-pmda-podman.x86_64                                 5.3.1-5.el8                                            AppStream 
    podman.x86_64                                          3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-catatonit.x86_64                                3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-docker.noarch                                   3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-gvproxy.x86_64                                  3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-plugins.x86_64                                  3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-remote.x86_64                                   3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    podman-tests.x86_64                                    3.3.1-9.module+el8.5.0+12697+018f24d7                  AppStream 
    python3-podman.noarch                                  3.2.0-2.module+el8.5.0+12582+56d94c81                  AppStream 
    [root@localhost ~]# yum -y install podman
    [root@localhost ~]# which podman
    /usr/bin/podman
    

    配置加速器

  [root@localhost ~]# cd /etc/containers/
  [root@localhost containers]# ls
  certs.d  policy.json      registries.conf.d  storage.conf
  oci      registries.conf  registries.d
  [root@localhost containers]# vim registries.conf
  #unqualified-search-registries = ["registry.fedoraproject.org","registry.access.redhat.com", "registry.centos.org", "docker.io"]    //注释
  unqualified-search-registries = ["docker.io"]  
  [[registry]]
  prefix = "docker.io"
  location = "bxrtqrie.mirror.aliyuncs.com"
  
  [root@localhost containers]# podman info  //查看是否配置成功
  ...
  registries:
    docker.io:
      Blocked: false
      Insecure: false
      Location: bxrtqrie.mirror.aliyuncs.com
      MirrorByDigestOnly: false
      Mirrors: null
      Prefix: docker.io
    search:
    - docker.io
  ...

Podman常用命令

运行容器

[root@localhost ~]# podman run -d --name web -p 80:80 httpd
3ab673e0e8aed9eeb334901708f46a968202271f00056ed0848020b238bf31c8

查看正在运行的容器

[root@localhost ~]# podman ps 
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS            PORTS               NAMES
3ab673e0e8ae  docker.io/library/httpd:latest  httpd-foreground  6 seconds ago  Up 6 seconds ago  0.0.0.0:80->80/tcp  web

查看镜像

[root@localhost ~]# podman images
REPOSITORY               TAG         IMAGE ID      CREATED       SIZE
docker.io/library/httpd  latest      dabbfbe0c57b  4 months ago  148 MB

列出所有容器

[root@localhost ~]# podman ps -a
CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS             PORTS               NAMES
3ab673e0e8ae  docker.io/library/httpd:latest  httpd-foreground  15 minutes ago  Up 15 minutes ago  0.0.0.0:80->80/tcp  web

查看最近一个容器的ip地址

[root@localhost ~]# podman inspect -l | grep IPAddress
            "IPAddress": "10.88.0.2",
                    "IPAddress": "10.88.0.2",
[root@localhost ~]# curl 10.88.0.2  //可以访问
<html><body><h1>It works!</h1></body></html>

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7vz2KidR-1652119629340)(C:\Users\10796\AppData\Roaming\Typora\typora-user-images\image-20220509215539840.png)]

查看最近一个容器的日志

[root@localhost ~]# podman logs --latest  //最近的
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.88.0.2. Set the 'ServerName' directive globally to suppress this message
[Mon May 09 13:52:44.959331 2022] [mpm_event:notice] [pid 1:tid 140213465468224] AH00489: Apache/2.4.52 (Unix) configured -- resuming normal operations
[Mon May 09 13:52:44.959588 2022] [core:notice] [pid 1:tid 140213465468224] AH00094: Command line: 'httpd -D FOREGROUND'
192.168.50.1 - - [09/May/2022:13:54:41 +0000] "GET /favicon.ico HTTP/1.1" 404 196
192.168.50.1 - - [09/May/2022:13:54:49 +0000] "GET / HTTP/1.1" 200 45
192.168.50.1 - - [09/May/2022:13:54:57 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [09/May/2022:13:54:59 +0000] "GET / HTTP/1.1" 304 -
192.168.50.1 - - [09/May/2022:13:55:49 +0000] "-" 408 -
10.88.0.1 - - [09/May/2022:14:03:57 +0000] "GET / HTTP/1.1" 200 45
192.168.50.1 - - [09/May/2022:14:17:06 +0000] "-" 408 -
192.168.50.1 - - [09/May/2022:14:17:06 +0000] "-" 408 -

删除最近一个容器

[root@localhost ~]# podman rm -f -l
3ab673e0e8aed9eeb334901708f46a968202271f00056ed0848020b238bf31c8
[root@localhost ~]# podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

查看进程查看一个运行容器中的进程资源使用情况

[root@localhost ~]# podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS             PORTS                 NAMES
39142c21904a  docker.io/library/httpd:latest  httpd-foreground  18 seconds ago  Up 18 seconds ago  0.0.0.0:8080->80/tcp  web
[root@localhost ~]# podman top web   //一个进程跑多个线程
USER        PID         PPID        %CPU        ELAPSED        TTY         TIME        COMMAND
root        1           0           0.000       20.710741094s  ?           0s          httpd -DFOREGROUND 
www-data    7           1           0.000       20.710903809s  ?           0s          httpd -DFOREGROUND 
www-data    8           1           0.000       20.710955906s  ?           0s          httpd -DFOREGROUND 
www-data    9           1           0.000       20.711013374s  ?           0s          httpd -DFOREGROUND 

停止一个运行中的容器

[root@localhost ~]# podman stop web
web
[root@localhost ~]# podman ps
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

删除一个容器

[root@localhost ~]# podman ps -a
CONTAINER ID  IMAGE                           COMMAND           CREATED        STATUS                     PORTS                 NAMES
39142c21904a  docker.io/library/httpd:latest  httpd-foreground  5 minutes ago  Exited (0) 56 seconds ago  0.0.0.0:8080->80/tcp  web
[root@localhost ~]# podman rm -f web
39142c21904a05a7560f223c5c7df9a04023ee9501c587d97f904f70d7641793
[root@localhost ~]# podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

用podmanfile制作镜像

root@localhost ~]# podman pull busybox   //拉镜像 
Resolved "busybox" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob 5cc84ad355aa done  
Copying config beae173cca done  
Writing manifest to image destination
Storing signatures
beae173ccac6ad749f76713cf4440fe3d21d1043fe616dfbe30775815d1d0f6a
[root@localhost ~]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED       SIZE
docker.io/library/busybox  latest      beae173ccac6  4 months ago  1.46 MB
docker.io/library/httpd    latest      dabbfbe0c57b  4 months ago  148 MB

[root@localhost ~]# ls
anaconda-ks.cfg
[root@localhost ~]# mkdir test
[root@localhost ~]# cd test/
[root@localhost test]# vim Podmanfile
[root@localhost test]# vim Podmanfile
[root@localhost test]# cat Podmanfile 
FROM busybox

ENV a 10
//当文件名不是dockerfile时用-f指定文件名
[root@localhost test]# podman build -f Podmanfile -t test:v01 .  
STEP 1/2: FROM busybox
STEP 2/2: ENV a 10
COMMIT test:v01
--> 08416526713
Successfully tagged localhost/test:v01
08416526713cc1ffb2cf235a60eba89690f28cd23adeff93252cf0105b589e3c

[root@localhost test]podman run -it test:v01 /bin/sh
/ # echo $a
10

上传镜像

修改镜像名

[root@localhost ~]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED         SIZE
localhost/test             v01         157fe36e560a  13 seconds ago  1.46 MB
docker.io/library/busybox  latest      beae173ccac6  4 months ago    1.46 MB
docker.io/library/httpd    latest      dabbfbe0c57b  4 months ago    148 MB
[root@localhost ~]# podman tag localhost/test:v01 docker.io/yyqxyyds/busybox:v01
[root@localhost ~]# podman images
REPOSITORY                  TAG         IMAGE ID      CREATED         SIZE
localhost/test              v01         157fe36e560a  48 seconds ago  1.46 MB
docker.io/yyqxyyds/busybox  v01         157fe36e560a  48 seconds ago  1.46 MB
docker.io/library/busybox   latest      beae173ccac6  4 months ago    1.46 MB
docker.io/library/httpd     latest      dabbfbe0c57b  4 months ago    148 MB

登录官方仓库上传镜像

[root@localhost ~]# podman login docker.io
Username: yyqxyyds
Password: 
Login Succeeded!
[root@localhost ~]# podman images
REPOSITORY                  TAG         IMAGE ID      CREATED        SIZE
localhost/test              v01         157fe36e560a  4 minutes ago  1.46 MB
docker.io/yyqxyyds/busybox  v01         157fe36e560a  4 minutes ago  1.46 MB
docker.io/library/busybox   latest      beae173ccac6  4 months ago   1.46 MB
docker.io/library/httpd     latest      dabbfbe0c57b  4 months ago   148 MB
[root@localhost ~]# podman push docker.io/yyqxyyds/busybox:v01
Getting image source signatures
Copying blob 01fd6df81c8e done  
Copying config 157fe36e56 done  
Writing manifest to image destination
Storing signatures

登录到官方仓库查看

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WhYvqlWN-1652119629342)(C:\Users\10796\AppData\Roaming\Typora\typora-user-images\image-20220509231212027.png)]

[root@localhost ~]# podman inspect docker.io/yyqxyyds/busybox:v01
[
    {
        "Id": "157fe36e560aaabc2ce2d1878e7b83a2eeb69b1551d365f2401f5eaed05120dc",
        "Digest": "sha256:2cc3f1edf4b7097e8270d4ea52e0f9e8ce2a51f71eefe86656697d6e5405035c",
        "RepoTags": [
            "localhost/test:v01",
            "docker.io/yyqxyyds/busybox:v01"
        ],
...

设置别名

如果习惯了使用 Docker 命令,可以直接给 Podman 配置一个别名来实现无缝转移

[root@localhost ~]# alias docker='podman' 
[root@localhost ~]# docker images
REPOSITORY                  TAG         IMAGE ID      CREATED         SIZE
localhost/test              v01         157fe36e560a  14 minutes ago  1.46 MB
docker.io/yyqxyyds/busybox  v01         157fe36e560a  14 minutes ago  1.46 MB
docker.io/library/busybox   latest      beae173ccac6  4 months ago    1.46 MB
docker.io/library/httpd     latest      dabbfbe0c57b  4 months ago    148 MB

用户操作

在允许没有root特权的用户运行Podman之前,管理员必须安装或构建Podman并完成以下配置

cgroup V2Linux内核功能允许用户限制普通用户容器可以使用的资源,如果使用cgroupV2启用了运行Podman的Linux发行版,则可能需要更改默认的OCI运行时。某些较旧的版本runc不适用于cgroupV2,必须切换到备用OCI运行时crun。

[root@localhost ~]# dnf list all|grep crun
crun.x86_64                                            1.0-1.module+el8.5.0+12582+56d94c81                    AppStream 
[root@localhost ~]# dnf -y install crun

[root@localhost ~]# cd /usr/share/containers/
[root@localhost containers]# ls
containers.conf  mounts.conf  seccomp.json  selinux
[root@localhost containers]# vim containers.conf 
runtime = "crun"   //取消注释
#runtime = "runc"   //注释
[root@localhost ~]# podman run -d httpd
cc2a14f34b0018e346990013cbf6d68e93e63853316748f5f564820edcb48007
[root@localhost ~]# podman inspect -l|grep -i runtime  //查看是否生效
        "OCIRuntime": "crun",
            "--runtime",
            "Runtime": "oci",
            "CpuRealtimeRuntime": 0,

安装slirp4netns和fuse-overlayfs

在普通用户环境中使用Podman时,建议使用fuse-overlayfs而不是VFS(virtual file system 虚拟文件系统)文件系统,至少需要版本0.7.6。现在新版本默认就是了。

[root@localhost ~]# dnf -y install slirp4netns 
[root@localhost ~]# dnf -y install fuse-overlayfs
[root@localhost ~]# cd /etc/containers/
[root@localhost containers]# ls
certs.d  policy.json      registries.conf.d  storage.conf
oci      registries.conf  registries.d
[root@localhost containers]# vim storage.conf 
mount_program = "/usr/bin/fuse-overlayfs"   //取消注释

/ etc / subuid和/ etc / subgid配置

Podman要求运行它的用户在/ etc / subuid和/ etc / subgid文件中列出一系列UID,shadow-utils或newuid包提供这些文件

[root@localhost containers]# dnf list all|grep shadow
shadow-utils.x86_64                                    2:4.6-14.el8                                           @anaconda 
[root@localhost containers]# rpm -qa|grep shadow
shadow-utils-4.6-14.el8.x86_64

可以在/ etc / subuid和/ etc / subgid查看,每个用户的值必须唯一且没有任何重叠。
[root@localhost ~]# cat /etc/subuid
[root@localhost ~]# cat /etc/subgid
[root@localhost ~]# useradd yyqx
[root@localhost ~]# cat /etc/subuid
yyqx:100000:65536
[root@localhost ~]# cat /etc/subgid
yyqx:100000:65536


// 启动非特权ping 
[root@localhost ~]#  vim /etc/sysctl.conf   //永久生效
net.ipv4.ping_group_range=0 200000   //大于100000这个就表示tom可以操作podman
[root@localhost ~]# sysctl -p  //立即生效
net.ipv4.ping_group_range = 0 200000

这个文件的格式是 USERNAME:UID:RANGE中/etc/passwd或输出中列出的用户名getpwent。

  • 为用户分配的初始 UID。
  • 为用户分配的 UID 范围的大小。

该usermod程序可用于为用户分配 UID 和 GID,而不是直接更新文件。

[root@localhost ~]# usermod --add-subuids 200000-201000 --add-subgids 200000-201000 yyqx1
[root@localhost ~]# grep yyqx1 /etc/subuid /etc/subgid
/etc/subuid:yyqx1:165536:65536
/etc/subgid:yyqx1:165536:65536

用户配置文件

三个主要的配置文件是container.confstorage.confregistries.conf。用户可以根据需要修改这些文件。

container.conf

// 用户配置文件
[root@localhost ~]# cat /usr/share/containers/containers.conf
[root@localhost ~]# cat /etc/containers/containers.conf
[root@localhost ~]# cat ~/.config/containers/containers.conf  //优先级最高

如果它们以该顺序存在。每个文件都可以覆盖特定字段的前一个文件。(当要修改的东西是同一个时优先级高的生效)

配置storage.conf文件

1./etc/containers/storage.conf
2.$HOME/.config/containers/storage.conf   

在普通用户中**/etc/containers/storage.conf**的一些字段将被忽略

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

# Default Storage Driver, Must be set for proper operation.
driver = "overlay"    //此处改为overlay
.......
mount_program = "/usr/bin/fuse-overlayfs"    //取消注释

如果版本为8以下,则需要做以下操作:
[root@localhost ~]# sysctl user.max_user_namespaces=15000   //临时
[root@localhost ~]# vim /etc/sysctl.conf  //永久生效
net.ipv4.ping_group_range=0 200000
user.max_user_namespaces=15000
[root@localhost ~]# sysctl -p
net.ipv4.ping_group_range = 0 200000
user.max_user_namespaces = 15000

在普通用户中这些字段默认

graphroot="$HOME/.local/share/containers/storage"
runroot="$XDG_RUNTIME_DIR/containers"

registries.conf

配置按此顺序读入,这些文件不是默认创建的,可以从**/usr/share/containers或复制文件/etc/containers**并进行修改。

1./etc/containers/registries.conf
2./etc/containers/registries.d/*
3.HOME/.config/containers/registries.conf

授权文件

此文件里面写了docker账号的密码,以加密方式显示

[root@localhost ~]# podman login
Username: yyqxyyds
Password: 
Login Succeeded!
[root@localhost ~]# cat /run/user/0/containers/auth.json 
{
	"auths": {
		"docker.io": {
			"auth": "eXlxeHl5ZHM6d2oxMjM0NTY3OA=="
		}
	}

普通用户是无法看见root用户的镜像的,root用户也不能看到普通用户的镜像

//root用户
[root@localhost ~]# podman images
REPOSITORY                  TAG         IMAGE ID      CREATED       SIZE
localhost/test              v01         157fe36e560a  2 hours ago   1.46 MB
docker.io/yyqxyyds/busybox  v01         157fe36e560a  2 hours ago   1.46 MB
docker.io/library/busybox   latest      beae173ccac6  4 months ago  1.46 MB
docker.io/library/httpd     latest      dabbfbe0c57b  4 months ago  148 MB

//普通用户
[yyqx@localhost ~]$ podman images
REPOSITORY  TAG         IMAGE ID    CREATED     SIZE
[yyqx@localhost ~]$ podman pull busybox
Resolved "busybox" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob 5cc84ad355aa done  
Copying config beae173cca done  
Writing manifest to image destination
Storing signatures
beae173ccac6ad749f76713cf4440fe3d21d1043fe616dfbe30775815d1d0f6a
[yyqx@localhost ~]$ podman images
REPOSITORY                 TAG         IMAGE ID      CREATED       SIZE
docker.io/library/busybox  latest      beae173ccac6  4 months ago  1.46 MB
[yyqx@localhost ~]$ podman run -it --rm busybox /bin/sh
/ # 

//root账户
[root@localhost ~]# podman ps   //不能查看,每个用户只能管理自己的
CONTAINER ID  IMAGE                           COMMAND           CREATED            STATUS                PORTS      httpd-foreground  About an hour ago  Up About an hour ago              nostalgic_blackburn

  • 容器与root用户一起运行,则root容器中的用户实际上就是主机上的用户。
  • UID GID是在/etc/subuid和/etc/subgid等中用户映射中指定的第一个UID GID。
  • 如果普通用户的身份从主机目录挂载到容器中,并在该目录中以根用户身份创建文件,则会看到它实际上是你的用户在主机上拥有的。

使用卷

[yyqx@localhost ~]$ mkdir data
[yyqx@localhost ~]$ ls
data
[yyqx@localhost ~]$ ll
total 0
drwxrwxr-x. 2 yyqx yyqx 6 May 10 01:30 data
[yyqx@localhost ~]$ pwd
/home/yyqx

//要加一个Z,表示放行selinux规则
[yyqx@localhost ~]$ podman run -it --rm -v "$(pwd)"/data:/data:Z busybox /bin/sh
/ # ls
bin   dev   home  root  sys   usr
data  etc   proc  run   tmp   var
/ # cd data/
/data # ls
/data # touch abc
/data # ls -l
total 0
-rw-r--r--    1 root     root             0 May  9 17:42 abc

[yyqx@localhost ~]$ ll data/
total 0
-rw-r--r--. 1 yyqx yyqx 0 May 10 01:42 abc
[yyqx@localhost ~]$ echo ' hello ' >  data/abc
/data # ls
abc
/data # cat abc
 hello 

使用普通用户映射容器端口时会报“ permission denied”的错误

[yyqx@localhost ~]$ podman run -d --name web -p 80:80 httpd
Resolving "httpd" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/library/httpd:latest...
Getting image source signatures
Copying blob dcc4698797c8 done  
Copying blob d982c879c57e done  
Copying blob 67283bbdd4a0 done  
Copying blob a2abf6c4d29d done  
Copying blob 41c22baa66ec done  
Copying config dabbfbe0c5 done  
Writing manifest to image destination
Storing signatures
Error: rootlessport cannot expose privileged port 80, you can add 'net.ipv4.ip_unprivileged_port_start=80' to /etc/sysctl.conf (currently 1024), or choose a larger port number (>= 1024): listen tcp 0.0.0.0:80: bind: permission denied
//除了管理员以外的其他用户不能暴露特权端口号80,1024以下的是特权端口号,只有管理员能控制
[yyqx@localhost ~]$ podman run -d --name web -p 8080:80 httpd
f43dc6b181d8b877124d4c63b23f26df57e8613a741773d15caf0ca11dcf0b1c
[yyqx@localhost ~]$ podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS             PORTS                 NAMES
f43dc6b181d8  docker.io/library/httpd:latest  httpd-foreground  13 seconds ago  Up 13 seconds ago  0.0.0.0:8080->80/tcp  web

如果普通用户想要使用80端口可以修改/etc/sysctl.conf文件让其生效
//需要切换到root用户修改
[root@localhost ~]#  vim /etc/sysctl.conf 
net.ipv4.ip_unprivileged_port_start=80   //添加此行
[root@localhost ~]# sysctl -p
net.ipv4.ping_group_range = 0 200000
user.max_user_namespaces = 15000
net.ipv4.ip_unprivileged_port_start = 80

//此时可以用80端口映射
[yyqx@localhost ~]$ podman run -d --name web1 -p 80:80 httpd
e45769bf0a3bb399f10b48654d6795deaea13735ed7518a79a3f3da4ca990b54
[yyqx@localhost ~]$ podman ps
CONTAINER ID  IMAGE                           COMMAND           CREATED         STATUS             PORTS               NAMES
e45769bf0a3b  docker.io/library/httpd:latest  httpd-foreground  11 seconds ago  Up 11 seconds ago  0.0.0.0:80->80/tcp  web1

 类似资料: