目录
- 1.podman介绍
- 2.与docker相比的优势
- 3.兼容性
- 4.后台服务单元文件的优先级
- 5.podman基本操作
- 安装
- 版本
- 仓库
- 命令帮助
- 镜像加速器
- 拉取镜像
- 6.运行一个web容器
- 后台启动一个web容器 , 并访问容器内容
- 暂停与删除容器
- 7.web容器设置开机自启
- 后台运行一个web容器
- 创建.service单元文件
- 查看生成的单元文件
- 删除刚才的容器
- 设置开机自启
1.podman介绍podman之前是CRI-O项目的一部分 , 后被分离成独立的项目libpod , libpod是一个创建容器pod的工具和库 , podman是个无守护程序容器引擎 , 以root用户或无根模式运行 , 简而言之podman提供了一个docker-CLI的命令行 , 管理着容器
2.与docker相比的优势docker劣势一:
docker大家都知道 , 其守护程序在多个核心上占用差不多高达100%cpu资源 , 采用C/S模型
podman优势一:
podman不需要守护进程 , 不需要root权限组 , 而且利用着用户命名空间(namespace)模拟容器中的root运行 , 采用fork/exec模型 。
fork/exec模型相比C/S模型优势:
- 系统管理员知道某个容器由谁启动
- 利用cgroup对podman做限制 , 对应着创建的容器也会受到限制
- systemd单元文件的生成 , 可以管理着任务的启动与关闭
- socket激活 , 将socker从systemd发送给podman容器使用
3.兼容性docker的功能大部分podman都是兼容的 , 也可以使用别名(alias)来写成docker的命令
4.后台服务单元文件的优先级
/usr/lib/systemd/user:优先级最低 , 会被优先级高的同名 unit 覆盖 ~/.local/share/systemd/user/etc/systemd/user:全局共享的用户级 unit[s]~/.config/systemd/user:优先级最高5.podman基本操作
安装#默认centos源[root@slave02 ~]# yum -ymodule install container-tools#容器工具基于模块[root@slave02 ~]# yum-y install podman-docker#安装docker兼容包(可选)
版本[root@slave02 ~]# podman -vpodman version 3.3.0-dev
仓库官方仓库:registry.access.redhat.com
【Podman开机自启容器实现过程及与Docker对比】第三方仓库:docker.io
私有仓库:registry.lab.example.com
命令帮助[root@slave02 ~]# podman help|head -15Manage pods, containers and imagesUsage:podman [options] [command]Available Commands:attachAttach to a running containerauto-update Auto update containers according to their auto-update policybuildBuild an image using instructions from ContainerfilescommitCreate new image based on the changed container#基于修改的容器创建新的容器containerManage containerscpCopy files/folders between a container and the local filesystemcreateCreate but do not start a containerdiff Display the changes to the object's file systemeventsShow podman events....
镜像加速器修改配置文件:/etc/containers/registries.conf 即可
注意:不能带有httpds//:url格式
[root@slave02 ~]# cp /etc/containers/registries.conf/backup/registries.conf.back#备份一下[root@slave02 ~]# vim/etc/containers/registries.confunqualified-search-registries = ["docker.io"]#非限定搜索登记处[[registry]]prefix = "docker.io"location = "x"#x是阿里加速镜像地址
拉取镜像[root@slave02 ~]# podman pull nginx
6.运行一个web容器
后台启动一个web容器 , 并访问容器内容#准备html页面内容[root@192 ~]# cat /opt/webhtml/index.html Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambition#运行一个守护web容器进程 , 将/opt/webhtml目录内容映射到容器的/usr/share/nginx/html存放网页的位置[root@192 ~]# podman run -d --name web -p 8888:80 -v /opt/webhtml:/usr/share/nginx/html nginx3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c[root@podman ~]# curl 192.168.136.129:8888Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambition#容器的ip[root@podman ~]# podman inspect web|grep IPAddress"IPAddress": "10.88.0.6","IPAddress": "10.88.0.6",#宿主机的ip[root@podman ~]# ip r192.168.136.0/24 dev ens33 proto kernel scope link src 192.168.136.129 metric 100 #由于进行了端口绑定 , 所以直接 curl 192.168.136.129:8888即可访问进入后台web容器 , 查看服务状态
[root@podman ~]# podman exec -itweb bashroot@3528e6d5148b:/# service nginx status[ ok ] nginx is running. #运行中修改容器业务内容
#修改宿主机/opt/webhtml/index.html即可[root@podman ~]# cat /opt/webhtml/index.html Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCASRHCE RHCA#进行访问[root@podman ~]# curl 192.168.136.129:8888Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS RHCE RHCA#进入容器查看内容是否修改[root@podman ~]# podman exec -it web bashroot@3528e6d5148b:/# cat /usr/share/nginx/html/index.html Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS RHCE RHCA
暂停与删除容器#暂停[root@podman ~]# podman stop webweb[root@podman ~]# podman ps -aCONTAINER IDIMAGECOMMAND CREATEDSTATUSPORTSNAMES3528e6d5148bdocker.io/library/nginx:latestnginx -g daemon o...25 minutes agoExited (0) 16 seconds ago0.0.0.0:8888->80/tcpweb#删除[root@podman ~]# podman rm web3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c#或强制删除运行中的容器[root@podman ~]# podman rm-f web3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
7.web容器设置开机自启
后台运行一个web容器[root@podman ~]# podman run --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a基于web容器 , 在优先级一般的/etc/systemd/system内
创建.service单元文件[root@192 ~]# cd /etc/systemd/system/[root@podman user]# podman generate systemd ----container-prefix(Systemd unit name prefix for containers)--files{生成.service文件 , 而不是打印到标准输出}--format(Print the created units in specified format (json)) #以指定的格式打印单元文件--name(Use container/pod names instead of IDs)#创建新容器 , 而不是使用现有的容器--new (Create a new container instead of starting an existing one)#(跳过标头生成)--no-header(Skip header generation)--pod-prefix (Systemd unit name prefix for pods)--restart-policy(Systemd restart-policy)--separator(Systemd unit name separator between name/id and prefix)--time(Stop timeout override)[root@192 system]# podman generate systemd --name web --files --new/etc/systemd/system/container-web.service
查看生成的单元文件[root@192 system]# cat container-web.service # container-web.service# autogenerated by Podman 3.3.0-dev#podman 3.3.0-dev自动生成# Tue Aug 17 13:03:13 CST 2021#8月17日星期二13:03:13 CST 2021[Unit]#单元Description=Podman container-web.service#描述Documentation=man:podman-generate-systemd(1)#帮助以及生成的系统Wants=network-online.target#网络After=network-online.targetRequiresMountsFor=%t/containers#前面不重要直接跳过[Service]Environment=PODMAN_SYSTEMD_UNIT=%nRestart=on-failure#故障时重新启动TimeoutStopSec=70#超时时间ExecStart=/usr/bin/podman run --sdnotify=conmon --cgroups=no-conmon --rm --replace --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx#执行开始为/usr/bin/podman运行刚才创建的容器Type=notifyNotifyAccess=all[Install]WantedBy=multi-user.target default.target
删除刚才的容器[root@podman ~]# podman rm web910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a[root@podman ~]# podman ps -aCONTAINER IDIMAGECOMMANDCREATEDSTATUSPORTSNAMES
设置开机自启[root@192 ~]# systemctl daemon-reload [root@192 ~]# systemctl enable --now container-web.service Created symlink /etc/systemd/system/multi-user.target.wants/container-web.service → /etc/systemd/system/container-web.service.Created symlink /etc/systemd/system/default.target.wants/container-web.service → /etc/systemd/system/container-web.service.[root@192 user]# podman ps -aCONTAINER IDIMAGECOMMAND CREATEDSTATUSPORTSNAMESb0c7709cb00edocker.io/library/nginx:latestnginx -g daemon o...15 seconds agoUp 16 seconds ago0.0.0.0:8080->80/tcpweb无根root模式设置容器和上面这种方式大同小异
使用systemctl命令带上 --user 即可
#需要运行loginctl enable-linger命令 , 使用户服务在服务器启动时自动启动即可[containers@serverb ~]$ loginctl enable-linger 以上就是Podman开机自启容器实现过程的详细内容 , 更多关于Podman开机自启容器的资料请关注考高分网其它相关文章!
- 春季老年人吃什么养肝?土豆、米饭换着吃
- 三八妇女节节日祝福分享 三八妇女节节日语录
- 老人谨慎!选好你的“第三只脚”
- 校方进行了深刻的反思 青岛一大学生坠亡校方整改校规
- 脸皮厚的人长寿!有这特征的老人最长寿
- 长寿秘诀:记住这10大妙招 100%增寿
- 春季老年人心血管病高发 3条保命要诀
- 眼睛花不花要看四十八 老年人怎样延缓老花眼
- 香槟然能防治老年痴呆症? 一天三杯它人到90不痴呆
- 老人手抖的原因 为什么老人手会抖
