一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

云服務(wù)器|WEB服務(wù)器|FTP服務(wù)器|郵件服務(wù)器|虛擬主機(jī)|服務(wù)器安全|DNS服務(wù)器|服務(wù)器知識(shí)|Nginx|IIS|Tomcat|

服務(wù)器之家 - 服務(wù)器技術(shù) - 服務(wù)器知識(shí) - Podman開機(jī)自啟容器實(shí)現(xiàn)過程及與Docker對(duì)比

Podman開機(jī)自啟容器實(shí)現(xiàn)過程及與Docker對(duì)比

2021-09-22 17:39神慕蔡蔡 服務(wù)器知識(shí)

這篇文章主要為大家介紹了Podman開機(jī)自啟容器實(shí)現(xiàn)過程,通過示例代碼的形式進(jìn)行演繹過程,有需要的朋友可以參考下,希望可以有所幫助

1.podman介紹

podman之前是CRI-O項(xiàng)目的一部分,后被分離成獨(dú)立的項(xiàng)目libpod,libpod是一個(gè)創(chuàng)建容器pod的工具和庫,podman是個(gè)無守護(hù)程序容器引擎,以root用戶或無根模式運(yùn)行,簡(jiǎn)而言之podman提供了一個(gè)docker-CLI的命令行,管理著容器

2.與docker相比的優(yōu)勢(shì)

docker劣勢(shì)一:

docker大家都知道,其守護(hù)程序在多個(gè)核心上占用差不多高達(dá)100%cpu資源,采用C/S模型

podman優(yōu)勢(shì)一:

podman不需要守護(hù)進(jìn)程,不需要root權(quán)限組,而且利用著用戶命名空間(namespace)模擬容器中的root運(yùn)行,采用fork/exec模型。

fork/exec模型相比C/S模型優(yōu)勢(shì):

  • 系統(tǒng)管理員知道某個(gè)容器由誰啟動(dòng)
  • 利用cgroup對(duì)podman做限制,對(duì)應(yīng)著創(chuàng)建的容器也會(huì)受到限制
  • systemd單元文件的生成,可以管理著任務(wù)的啟動(dòng)與關(guān)閉
  • socket激活,將socker從systemd發(fā)送給podman容器使用

3.兼容性

docker的功能大部分podman都是兼容的,也可以使用別名(alias)來寫成docker的命令

4.后臺(tái)服務(wù)單元文件的優(yōu)先級(jí)

/usr/lib/systemd/user:優(yōu)先級(jí)最低,會(huì)被優(yōu)先級(jí)高的同名 unit 覆蓋 ~/.local/share/systemd/user

/etc/systemd/user:全局共享的用戶級(jí) unit[s]

~/.config/systemd/user:優(yōu)先級(jí)最高

5.podman基本操作

安裝

?
1
2
3
#默認(rèn)centos源
[root@slave02 ~]# yum -y  module install container-tools   #容器工具基于模塊
[root@slave02 ~]# yum  -y install podman-docker            #安裝docker兼容包(可選)

版本

?
1
2
[root@slave02 ~]# podman -v
podman version 3.3.0-dev

倉庫

官方倉庫:registry.access.redhat.com

第三方倉庫:docker.io

私有倉庫:registry.lab.example.com

命令幫助

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@slave02 ~]# podman help|head -15
Manage pods, containers and images
Usage:
  podman [options] [command]
Available Commands:
  attach      Attach to a running container
  auto-update Auto update containers according to their auto-update policy
  build       Build an image using instructions from Containerfiles
  commit      Create new image based on the changed container  #基于修改的容器創(chuàng)建新的容器
  container   Manage containers
  cp          Copy files/folders between a container and the local filesystem
  create      Create but do not start a container
  diff        Display the changes to the object's file system
  events      Show podman events
....

鏡像加速器

修改配置文件:/etc/containers/registries.conf 即可

注意:不能帶有httpds//:url格式

?
1
2
3
4
5
6
[root@slave02 ~]# cp /etc/containers/registries.conf  /backup/registries.conf.back  #備份一下         
[root@slave02 ~]# vim  /etc/containers/registries.conf
unqualified-search-registries = ["docker.io"]           #非限定搜索登記處
[[registry]]
prefix = "docker.io"
location = "x"             #x是阿里加速鏡像地址

拉取鏡像

?
1
[root@slave02 ~]# podman pull nginx

6.運(yùn)行一個(gè)web容器

后臺(tái)啟動(dòng)一個(gè)web容器,并訪問容器內(nèi)容

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#準(zhǔn)備html頁面內(nèi)容
[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
#運(yùn)行一個(gè)守護(hù)web容器進(jìn)程,將/opt/webhtml目錄內(nèi)容映射到容器的/usr/share/nginx/html存放網(wǎng)頁的位置
[root@192 ~]# podman run -d --name web -p 8888:80 -v /opt/webhtml:/usr/share/nginx/html nginx
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
[root@podman ~]# curl 192.168.136.129:8888
Go 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",
#宿主機(jī)的ip
[root@podman ~]# ip r
192.168.136.0/24 dev ens33 proto kernel scope link src 192.168.136.129 metric 100
#由于進(jìn)行了端口綁定,所以直接 curl 192.168.136.129:8888即可訪問

進(jìn)入后臺(tái)web容器,查看服務(wù)狀態(tài)

?
1
2
3
[root@podman ~]# podman exec -it  web bash
root@3528e6d5148b:/# service nginx status
[ ok ] nginx is running.                             #運(yùn)行中

修改容器業(yè)務(wù)內(nèi)容

?
1
2
3
4
5
6
7
8
9
10
11
12
13
#修改宿主機(jī)/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 ambitionRHCAS
RHCE RHCA
#進(jìn)行訪問
[root@podman ~]# curl 192.168.136.129:8888
Go your own way, see your own scenery, surpass others without complacency, and be surpassed without losing ambitionRHCAS
RHCE RHCA
#進(jìn)入容器查看內(nèi)容是否修改
[root@podman ~]# podman exec -it web bash
root@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

暫停與刪除容器

?
1
2
3
4
5
6
7
8
9
10
11
12
#暫停
[root@podman ~]# podman stop web
web
[root@podman ~]# podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS                     PORTS                 NAMES
3528e6d5148b  docker.io/library/nginx:latest  nginx -g daemon o...  25 minutes ago  Exited (0) 16 seconds ago  0.0.0.0:8888->80/tcp  web
#刪除
[root@podman ~]# podman rm web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
#或強(qiáng)制刪除運(yùn)行中的容器
[root@podman ~]# podman rm  -f web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c

7.web容器設(shè)置開機(jī)自啟

后臺(tái)運(yùn)行一個(gè)web容器

?
1
2
[root@podman ~]# podman run --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx
910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a

基于web容器,在優(yōu)先級(jí)一般的/etc/systemd/system內(nèi)

創(chuàng)建.service單元文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@192 ~]# cd /etc/systemd/system/
[root@podman user]# podman generate systemd --
--container-prefix  (Systemd unit name prefix for containers)
--files             {生成.service文件,而不是打印到標(biāo)準(zhǔn)輸出}
--format            (Print the created units in specified format (json)) #以指定的格式打印單元文件
--name              (Use container/pod names instead of IDs)  #創(chuàng)建新容器,而不是使用現(xiàn)有的容器
--new               (Create a new container instead of starting an existing one)#(跳過標(biāo)頭生成)
--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

查看生成的單元文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@192 system]# cat container-web.service
# container-web.service
# autogenerated by Podman 3.3.0-dev                                 #podman 3.3.0-dev自動(dòng)生成
# 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)          #幫助以及生成的系統(tǒng)
Wants=network-online.target                           #網(wǎng)絡(luò)
After=network-online.target
RequiresMountsFor=%t/containers                         #前面不重要直接跳過
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n                  
Restart=on-failure                  #故障時(shí)重新啟動(dòng)
TimeoutStopSec=70                   #超時(shí)時(shí)間   
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   #執(zhí)行開始為/usr/bin/podman  運(yùn)行剛才創(chuàng)建的容器
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target default.target

刪除剛才的容器

?
1
2
3
4
[root@podman ~]# podman rm web
910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a
[root@podman ~]# podman ps -a
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

設(shè)置開機(jī)自啟

?
1
2
3
4
5
6
7
[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 -a
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                   NAMES
b0c7709cb00e  docker.io/library/nginx:latest  nginx -g daemon o...  15 seconds ago  Up 16 seconds ago  0.0.0.0:8080->80/tcp    web

無根root模式設(shè)置容器和上面這種方式大同小異

使用systemctl命令帶上 --user 即可

?
1
2
#需要運(yùn)行l(wèi)oginctl enable-linger命令,使用戶服務(wù)在服務(wù)器啟動(dòng)時(shí)自動(dòng)啟動(dòng)即可
[containers@serverb ~]$ loginctl enable-linger

以上就是Podman開機(jī)自啟容器實(shí)現(xiàn)過程的詳細(xì)內(nèi)容,更多關(guān)于Podman開機(jī)自啟容器的資料請(qǐng)關(guān)注服務(wù)器之家其它相關(guān)文章!

原文鏈接:https://blog.csdn.net/qq_47945825/article/details/119754888

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲免费在线视频 | 狠狠色伊人亚洲综合网站色 | 国产精品 视频一区 二区三区 | 九九久久国产 | 日韩大片在线播放 | 午夜精品久久久久久 | 深夜激情网 | 欧美艳星kagneyiynn高清 | 本土自拍 | 大又大又粗又爽女人毛片 | 国产精品日韩欧美一区二区 | 91大神第九部红酒气质女 | 日韩精品一区二区三区中文字幕 | 成人性爱视频在线观看 | 国产一区二区三区欧美 | 草逼网站视频 | 99在线精品免费视频 | 91久久综合 | 国产盗摄wc厕所撒尿视频 | 双性鞭蒂软汁淋漓 | 国产精品人人视频 | 桃乃木香奈作品在线观看 | 青青青手机视频在线观看 | 能播放的欧美同性videos | freexxxx性护士第一次 | 99热这里只有精品国产免费 | 高h生子双性美人受 | www.好吊操| 日本中文字幕一区二区高清在线 | 俄罗斯性高清完整版 | 国产xx肥老妇视频奂费 | 欧美乱子伦xxxx12在线 | 成人影院www在线观看 | 国产成人理在线观看视频 | 成人高清网站 | 国产盗摄wc厕所撒尿视频 | 国产99视频精品免费视频7 | 性派对videos18party | 9久热这里只有精品视频在线观看 | 91高清国产经典在线观看 | 女学生被老师调教在教室 |