centos 7安装podman(类似docker)

16 篇文章 0 订阅
4 篇文章 0 订阅

Podman 是一个无守护、开源的 Linux 本地工具,旨在使用 open Containers Initiative (OCI) 让容器和镜像更加方便地查找、运行、构建、共享和部署应用程序。Podman 提供了一个命令行接口(CLI),任何使用过 Docker 容器引擎的人都能很快上手 podman。大多数用户可以简单地将 Podman 别名为 Docker (alias Docker = Podman),没有任何问题。与其他常见的容器引擎 (Docker、CRI-O、containerd) 类似,Podman 依赖于符合 OCI 的容器运行时(runc、cron、runv等) 来与操作系统交互并创建运行的容器。这使得由 Podman 创建的正在运行的容器与由任何其他通用容器引擎创建的容器几乎没有区别。
在这里插入图片描述

参考

CentOS7/8安装容器管理工具Podman
centos7 安装podman
podman入门实践
Podman Desktop 能否取代 Docker Desktop呢?
podman 配置国内镜像
podman镜像加速配置
Podman+Nginx创建带自启动的源站点
使用Podman建立容器
Centos8安装podman,自定义修改镜像,保存本地容器到私有仓库
Docker离线部署images及启动容器
podman案例:打包本地镜像,发送给别人或者上传镜像
CentOS 7 上编译安装 Podman 3.4.4
Podman 介绍,安装,基本操作
如何在Ubuntu 20.04上安装和使用Podman(Docker替代方案)?

yum安装-版本低

安装命令

# yum 搜索
yum search podman
# 安装
yum -y install podman
######
已安装:
  podman.x86_64 0:1.6.4-32.el7_9                                                                                                                             

作为依赖被安装:
  conmon.x86_64 2:2.0.8-1.el7                                            container-selinux.noarch 2:2.119.2-1.911c772.el7_8                                 
  containernetworking-plugins.x86_64 0:0.8.3-3.el7.centos                containers-common.x86_64 1:0.1.40-11.el7_8                                         
  criu.x86_64 0:3.12-2.el7                                               fuse-overlayfs.x86_64 0:0.7.2-6.el7_8                                              
  fuse3-libs.x86_64 0:3.6.1-4.el7                                        libnet.x86_64 0:1.1.6-7.el7                                                        
  libnftnl.x86_64 0:1.0.8-3.el7                                          nftables.x86_64 1:0.8-14.el7                                                       
  protobuf-c.x86_64 0:1.0.2-3.el7                                        python-dmidecode.x86_64 0:3.12.2-4.el7                                             
  python-syspurpose.x86_64 0:1.24.51-1.el7.centos                        runc.x86_64 0:1.0.0-69.rc10.el7_9                                                  
  slirp4netns.x86_64 0:0.4.3-4.el7_8                                     subscription-manager.x86_64 0:1.24.51-1.el7.centos                                 
  subscription-manager-rhsm.x86_64 0:1.24.51-1.el7.centos                subscription-manager-rhsm-certificates.x86_64 0:1.24.51-1.el7.centos
######
# 版本
podman -v
# podman version 1.6.4

在这里插入图片描述

支持的命令

podman --help
##--------
可用命令:
  attach      连接到运行的容器
  build       使用Containerfiles中的说明构建image
  commit      基于更改的容器创建新image
  container   管理容器
  cp          在容器和本地文件系统之间复制文件/文件夹
  create      创建但不启动容器
  diff        检查容器文件系统上的更改
  events      显示podman事件
  exec        在正在运行的容器中运行进程
  export      将容器的文件系统内容导出为tar归档
  generate    生成的结构化数据
  healthcheck 管理健康检查
  help        关于任何命令的帮助
  history     显示指定image的历史记录
  image       管理图像
  images      列出本地存储中的images
  import      导入tarball以创建文件系统images
  info        显示podman系统信息
  init        初始化一个或多个容器
  inspect     显示容器或image的配置
  kill        使用特定信号杀死一个或多个正在运行的容器
  load        从容器存档加载image
  login       登录到容器注册表
  logout      注销容器注册表
  logs        获取容器的日志
  mount       装载工作容器的根文件系统
  network     管理网络
  pause       暂停一个或多个容器中的所有进程
  play        播放Podman
  pod         管理POD
  port        列出容器的端口映射或特定映射
  ps          列出容器
  pull        从注册表中提取image
  push        将image推送到指定的目标
  restart     重新启动一个或多个容器
  rm          移除一个或多个容器
  rmi         从本地存储中删除一个或多个图像
  run         在新容器中运行命令
  save        将image保存到存档
  search      在注册表中搜索image
  start       启动一个或多个容器
  stats       显示容器资源使用统计信息的实时流
  stop        停止一个或多个容器
  system      管理Podman
  tag         向本地image添加其他名称
  top         显示容器的运行进程
  umount      卸载工作容器的根文件系统
  unpause     取消暂停一个或多个容器中的进程
  unshare     在修改的用户命名空间中运行命令
  varlink     运行varlink接口
  version     显示Podman版本信息
  volume      管理卷
  wait        阻止一个或多个容器

标志:
      --cgroup-manager string     要使用的Cgroup管理器(cgroupfs或systemd)(默认为“systemd”)
      --cni-config-dir string     CNI网络配置目录路径
      --config string             详细说明容器服务器配置选项的libpod配置文件的路径
      --conmon string             conmon二进制文件的路径
      --cpu-profile string        cpu分析结果的路径
      --events-backend string     要使用的事件后端
      --help                      Podman帮助
      --hooks-dir strings         设置OCI挂钩目录路径(可以多次设置)
      --log-level string          高于指定级别的日志消息:调试、信息、警告、错误、致命或死机(默认为“错误”)
      --namespace string          设置libpod名称空间,用于在系统上创建容器和pod的单独视图
      --network-cmd-path string   用于配置网络的命令的路径
      --root string               存储数据(包括image)的根目录的路径
      --runroot string            存储所有状态信息的“运行目录”的路径
      --runtime string            用于运行容器的OCI兼容二进制文件的路径,默认为/usr/bin/runc
      --storage-driver string     选择用于管理image和容器存储的存储驱动程序(默认为覆盖)
      --storage-opt stringArray   用于将选项传递给存储驱动程序
      --syslog                    将日志记录信息输出到syslog和控制台
      --tmpdir string             tmp目录的路径
      --trace                     启用opentracing输出
  -v, --version                   podman版本
##--------

镜像地址修改

podman 全局配置文件:/etc/containers/registries.conf
用户单独配置文件:~/.config/containers/registries.conf

cat /etc/containers/registries.conf
# 备份
cp /etc/containers/registries.conf /etc/containers/registries.conf.bak
vim /etc/containers/registries.conf
#######
# 为了确保与docker的兼容性,我们加入了docker。默认搜索列表中的io。然而,红帽不管理、修补或维护docker的容器图像。io注册表。
[registries.search]
registries = ["docker.io", "registry.fedoraproject.org", "registry.access.redhat.com","registry.redhat.io", "registry.centos.org"]
#########

当前问题-连不上源网站

搜索可以,下载不行。可能是版本太低

podman search nginx
podman pull nginx

在这里插入图片描述
在这里插入图片描述

卸载

CentOS 下 rpm包与 yum 安装与卸载

# 查询一个包是否被安装
rpm -q podman
# 卸载
rpm -e podman
rm -rf /etc/containers

在这里插入图片描述

源码安装

centos 7 支持最高版本为 3.4.4

  1. golang 安装(当前最新版本: 1.18)
  2. conmon 安装(当前最新版本: 2.1.0)
  3. runc 安装(当前最新版本: 1.1.1)
  4. podman安装(centos 7支持最高版本: 3.4.4)

安装go

# 临时关闭selinux
setenforce 0
# 安装golang,版本需要在 v1.6 以上
wget https://golang.google.cn/dl/go1.18.linux-amd64.tar.gz
tar xf go1.18.linux-amd64.tar.gz
mv go /usr/local/
ln -s /usr/local/go/bin/go /usr/local/bin/go
go version
# go version go1.18 linux/amd64

在这里插入图片描述

安装依赖

#  安装依赖
yum install -y \
  btrfs-progs-devel \
  containernetworking-plugins \
  containers-common \
  crun \
  device-mapper-devel \
  glib2-devel \
  glibc-devel \
  glibc-static \
  golang-github-cpuguy83-md2man \
  gpgme-devel \
  iptables \
  libassuan-devel \
  libgpg-error-devel \
  libseccomp-devel \
  libselinux-devel \
  make \
  pkgconfig

在这里插入图片描述

安装conmon 和 runc

# conmon是用C语言编写的工具,用于单个容器的管理器
wget https://github.com/containers/conmon/archive/refs/tags/v2.1.0.tar.gz
tar xf v2.1.0.tar.gz
cd conmon-2.1.0/
export GOCACHE="$(mktemp -d)"
make
make podman
#install  -D -m 755 bin/conmon /usr/local/libexec/podman/conmon
conmon --version
#conmon version 2.0.8
#commit: f85c8b1ce77b73bcd48b2d802396321217008762

# runc是golang写的关于CLI工具,用于根据OCI规范在 Linux上生成和运行容器
wget https://github.com/opencontainers/runc/releases/download/v1.1.1/runc.amd64
chmod +x runc.amd64
mv runc.amd64 /usr/local/bin/runc
/usr/local/bin/runc -version
#runc version 1.1.1
#commit: v1.1.0-20-g52de29d7
#spec: 1.0.2-dev
#go: go1.17.6
#libseccomp: 2.5.3

在这里插入图片描述

设置CNI网络

mkdir /etc/containers
wget https://src.fedoraproject.org/rpms/containers-common/raw/main/f/registries.conf
wget https://src.fedoraproject.org/rpms/containers-common/raw/main/f/default-policy.json
cp default-policy.json /etc/containers/default-policy.json
cp registries.conf /etc/containers/registries.conf
# 默认情况下,CNI网络配置文件下载好后,无需配置,即可使用 podman
# registries.conf: 容器镜像注册配置文件,文件格式为 TOML
# policy.json:证书安全策略文件,文件格式为 JSON

在这里插入图片描述

安装podman

wget https://github.com/containers/podman/archive/refs/tags/v3.4.4.tar.gz
tar xf v3.4.4.tar.gz
cd podman-3.4.4/
make BUILDTAGS="selinux seccomp"
# git clone -- https://github.com/cpuguy83/go-md2man /root/go/src/github.com/cpuguy83/go-md2man 超时问题
vim Makefile
####
# 800行 github.com/cpuguy83/go-md2man 改为
gitee.com/mirrors/go-md2man
####
# 再次make
make BUILDTAGS="selinux seccomp"
make install PREFIX=/usr
# 会自动在usr的bin、lib、share 中 创建相关内容
podman --version
# podman version 3.4.4
podman version
#Version:      3.4.4
#API Version:  3.4.4
#Go Version:   go1.18
#Built:        Wed Jun 29 15:51:56 2022
#OS/Arch:      linux/amd64

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

命令变化

# 移除
varlink     #运行varlink接口
--config string            # 详细说明容器服务器配置选项的libpod配置文件的路径
--cpu-profile string        #cpu分析结果的路径
--trace                     #启用opentracing输出
# 新增
auto-update #根据容器的自动更新策略自动更新容器
machine     #管理虚拟机
manifest    #操作清单列表和图像索引
rename      #重命名现有容器
secret      #管理机密
untag       #从本地映像中删除名称
-c, --connection string #用于远程Podman服务的连接
--identity string       #SSH标识文件的路径,(CONTAINER_SSHKEY)
-r, --remote            #访问远程Podman服务(默认为false)
--url string #访问Podman服务(CONTAINER_HOST)的URL(默认为“unix:/run/Podman/Podman.sock”)
# 变化
--events-backend string #要使用的事件后端(“file”|“journald”|“none”)(默认为“file”)
--hooks-dir strings #设置OCI挂钩目录路径(可以多次设置)(默认值[/usr/share/containers/OCI/hooks.d])
--tmpdir string #libpod状态内容的tmp目录路径。
                #注意:使用环境变量“TMPDIR”更改容器映像的临时存储位置“/var/tmp”。

运行hello-Word

mv /etc/containers/default-policy.json  /etc/containers/policy.json
podman run hello-world
podman ps -a
podman images

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

nginx映像拉取并使用

拉取镜像

podman pull nginx:alpine
podman images

在这里插入图片描述
在这里插入图片描述

运行镜像

podman run -it --rm -d -p 6080:80 --name web nginx:alpine
#-i或**--interactive**:保持容器 STDIN 打开,即使未附加。
#-t或 --tty:分配一个伪终端,将您的终端与容器的 STDIN 和 STDOUT 连接起来。
#--rm:当容器退出或停止时自动删除容器。
#-d:在后台运行容器,运行后分离容器。
#-p 8080:80:映射容器和主机系统之间的端口。容器上的端口“80”映射到主机系统端口“8080”。
#--name web:将新容器名称指定为“web”。
#nginx:alpine :我们使用的图像是'nginx:alpine'。
## 打开您的网络浏览器并使用端口“6080”访问您的服务器 IP 地址

在这里插入图片描述
在这里插入图片描述

查看日志

# 查看容器日志、最后几行
podman logs web
podman logs --tail 10 web

在这里插入图片描述

停止并检查

# 停止并检查
podman stop web
podman ps
podman ps -a

在这里插入图片描述

自定义目录挂载到镜像

mkdir /root/podman/nginx-vm
vim /root/podman/nginx-vm/index.html
# 使用自定义页面启动容器
podman run -it --rm -d -p 6080:80 --name web -v /root/podman/nginx-vm:/usr/share/nginx/html nginx:alpine
# -v:指定容器的卷。'/root/podman/nginx-vm' 目录将挂载到容器目录 '/usr/share/nginx/html'

index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Welcome to 容器 Nginx</title>
</head>
<body>
  <h2>Hello from Nginx 容器 - Managed with Podman</h2>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

进入镜像

podman exec -it web /bin/sh
hostname
ip a
route -n
exit # 退出

在这里插入图片描述

END

pod的部署和使用,就到这里。podman管理有时间了再弄

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值