Podman容器技术


什么是Podman

Podman 是一个无守护进程容器引擎,用于在 Linux 系统上开发、管理和运行 OCI 容器。Podman 提供与 Docker 非常相似的功能,它不需要在你的系统上运行任何守护进程,并且它也可以在没有 root 权限的情况下运行。

Podman与Docker的区别

  • docker在实现CRI的时候,它需要一个守护进程,其次需要以root运行。
  • podman不需要守护程序,也不需要root用户运行
  • 在docker的运行体系中,需要多个daemon才能调用到OCI的实现RunC
  • daemon,它在linux中需要以root运行,dockerd调用containerd,containerd调用containerd-shim,然后才能调用runC。顾名思义shim起的作用也就是“垫片”,避免父进程退出影响容器运行
  • podman直接调用OCI,runC,通过common作为容器进程的管理工具,但不需要dockerd这种以root身份运行的守护进程
  • common其运行路径通常是/usr/libexec/podman/conmon,它是各个容器进程的父进程,每个容器各有一个,podman中的common其实相当于docker体系中的containerd-shim

Podman与Docker在使用上的区别

Podman 和 Docker 是整体兼容的,Podman在使用上面比较靠近docker

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

Podman常用命令

容器

podman run           //创建并启动容器
podman start         //启动容器
podman ps            //查看容器
podman stop          //终止容器
podman restart       //重启容器
podman attach        //进入容器
podman exec          //进入容器
podman export        //导出容器
podman import        //导入容器快照
podman rm            //删除容器
podman logs          //查看日志

镜像

podman search                //检索镜像
podman pull                  //获取镜像
podman images                //列出镜像
podman image Is              //列出镜像
podman rmi                   //删除镜像
podman image rm              //删除镜像
podman save                  //导出镜像
podman load                  //导入镜像
podmanfile                   //定制镜像(三个)
  podman build               //构建镜像
    podman run               //运行镜像
    podmanfile               //常用指令(四个)
      COPY                   //复制文件
        ADD                  //高级复制
        CMD                  //容器启动命令
        ENV                  //环境变量
        EXPOSE               //暴露端口

Podman部署

安装podman

[root@100 ~]# yum -y install podman

部署加速器

[root@100 ~]# vim /etc/containers/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 = "cj9sucfo.mirror.aliyuncs.com"

Podman命令使用

镜像

搜索镜像

[root@100 ~]# podman search centos
INDEX       NAME                                                  DESCRIPTION                                      STARS       OFFICIAL    AUTOMATED
docker.io   docker.io/library/centos                              The official build of CentOS.                    7278        [OK]

获取镜像

[root@100 ~]# podman pull docker.io/library/centos
Trying to pull docker.io/library/centos:latest...
Getting image source signatures
Copying blob a1d0c7532777 done
Copying config 5d0da3dc97 done
Writing manifest to image destination
Storing signatures
5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6

查看镜像

[root@100 ~]# podman images
REPOSITORY             TAG         IMAGE ID      CREATED        SIZE
docker.io/library/centos  latest      5d0da3dc9764  11 months ago  239 MB

删除镜像

[root@100 ~]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED        SIZE
docker.io/frices/centos    v1          beae173ccac6  7 months ago   1.46 MB
docker.io/library/busybox  latest      beae173ccac6  7 months ago   1.46 MB
docker.io/library/centos   latest      5d0da3dc9764  11 months ago  239 MB
[root@100 ~]# podman rmi docker.io/frices/centos:v1
Untagged: docker.io/frices/centos:v1
[root@100 ~]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED        SIZE
docker.io/library/busybox  latest      beae173ccac6  7 months ago   1.46 MB
docker.io/library/centos   latest      5d0da3dc9764  11 months ago  239 MB

导出镜像

[root@100 ~]# podman save docker.io/library/busybox:latest > busy.tar
[root@100 ~]# ls busy.tar
busy.tar

导入镜像

[root@100 ~]# podman images
REPOSITORY                TAG         IMAGE ID      CREATED        SIZE
docker.io/library/centos  latest      5d0da3dc9764  11 months ago  239 MB
[root@100 ~]# podman load < busy.tar
Getting image source signatures
Copying blob 01fd6df81c8e done
Copying config beae173cca done
Writing manifest to image destination
Storing signatures
Loaded image(s): docker.io/library/busybox:latest
[root@100 ~]# podman images
REPOSITORY                 TAG         IMAGE ID      CREATED        SIZE
docker.io/library/busybox  latest      beae173ccac6  7 months ago   1.46 MB
docker.io/library/centos   latest      5d0da3dc9764  11 months ago  239 MB

容器

创建并运行容器

[root@100 ~]# podman run -dit --name test1 docker.io/library/centos
13057983d48ab42b3cf437aca3a16d05ff22c3489e6252e4bf214a3cdfd0551f

查看容器

[root@100 ~]# podman ps -a
CONTAINER ID  IMAGE                            COMMAND     CREATED         STATUS             PORTS       NAMES
13057983d48a  docker.io/library/centos:latest  /bin/bash   26 seconds ago  Up 26 seconds ago              test1

停止容器

[root@100 ~]# podman stop test1
test1
[root@100 ~]# podman ps -a
CONTAINER ID  IMAGE                            COMMAND     CREATED             STATUS                    PORTS       NAMES
13057983d48a  docker.io/library/centos:latest  /bin/bash   About a minute ago  Exited (0) 6 seconds ago              test1

启动容器

[root@100 ~]# podman start test1
test1
[root@100 ~]# podman ps
CONTAINER ID  IMAGE                            COMMAND     CREATED        STATUS            PORTS       NAMES
13057983d48a  docker.io/library/centos:latest  /bin/bash   2 minutes ago  Up 4 seconds ago              test1

登录docker.io

[root@100 ~]# podman login docker.io
Username: frices
Password:
Login Succeeded!

用容器制作镜像

[root@100 ~]# podman commit -p test1 docker.io/frices/centos/centos:v1
Getting image source signatures
Copying blob 74ddd0ec08fa skipped: already exists
Copying blob 8c94c75bb2e8 done
Copying config 0489aed707 done
Writing manifest to image destination
Storing signatures
0489aed707b93dbfc51910f75c1bfca3d70e84c0448ffb3f975b9e65a1ee7e15
[root@100 ~]# podman images
REPOSITORY                      TAG         IMAGE ID      CREATED        SIZE
docker.io/frices/centos/centos  v1          0489aed707b9  4 seconds ago  239 MB

上传镜像

[root@100 ~]# podman push docker.io/frices/centos:v1
Getting image source signatures
Copying blob 01fd6df81c8e done
Copying config beae173cca done
Writing manifest to image destination
Storing signatures

下载镜像

[root@100 ~]# podman pull frices/centos:v1
Resolving "frices/centos" using unqualified-search registries (/etc/containers/registries.conf)
Trying to pull docker.io/frices/centos:v1...
Getting image source signatures
Copying blob 900aaabb02f1 skipped: already exists
Copying config beae173cca done
Writing manifest to image destination
Storing signatures
beae173ccac6ad749f76713cf4440fe3d21d1043fe616dfbe30775815d1d0f6a

进入容器

[root@100 ~]# podman exec -it test1 /bin/bash
[root@f5173820781a /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

查看容器信息

[root@100 ~]# podman inspect test1
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "docker.io/library/centos:latest",

删除容器

[root@100 ~]# podman rm -f test1
f5173820781a910e512edf9c4017d8bef8824d2d355d2c284318c3d2943f2421
[root@100 ~]# podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值