濮阳杆衣贸易有限公司

主頁 > 知識庫 > Podman開機自啟容器實現(xiàn)過程及與Docker對比

Podman開機自啟容器實現(xiàn)過程及與Docker對比

熱門標簽:貴陽教育行業(yè)電話外呼系統(tǒng) 在百度地圖標注車輛 威海人工外呼系統(tǒng)供應商 撫順移動400電話申請 寧夏房產(chǎn)智能外呼系統(tǒng)要多少錢 藍點外呼系統(tǒng) 烏海智能電話機器人 做外呼系統(tǒng)的公司違法嗎 400電話申請方案

1.podman介紹

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

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

docker劣勢一:

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

podman優(yōu)勢一:

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

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

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

3.兼容性

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

4.后臺服務單元文件的優(yōu)先級

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

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

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

5.podman基本操作

安裝

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

版本

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

倉庫

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

第三方倉庫:docker.io

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

命令幫助

[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格式

[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是阿里加速鏡像地址

拉取鏡像

[root@slave02 ~]# podman pull nginx

6.運行一個web容器

后臺啟動一個web容器,并訪問容器內(nèi)容

#準備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
#運行一個守護web容器進程,將/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",
#宿主機的ip
[root@podman ~]# ip r
192.168.136.0/24 dev ens33 proto kernel scope link src 192.168.136.129 metric 100 
#由于進行了端口綁定,所以直接 curl 192.168.136.129:8888即可訪問

進入后臺web容器,查看服務狀態(tài)

[root@podman ~]# podman exec -it  web bash
root@3528e6d5148b:/# service nginx status
[ ok ] nginx is running.                             #運行中

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

#修改宿主機/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
#進行訪問
[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
#進入容器查看內(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

暫停與刪除容器

#暫停
[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
#或強制刪除運行中的容器
[root@podman ~]# podman rm  -f web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c

7.web容器設置開機自啟

后臺運行一個web容器

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

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

創(chuàng)建.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)  #創(chuàng)建新容器,而不是使用現(xiàn)有的容器
--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)          #幫助以及生成的系統(tǒng)
Wants=network-online.target                           #網(wǎng)絡
After=network-online.target
RequiresMountsFor=%t/containers                         #前面不重要直接跳過
[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n                   
Restart=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   #執(zhí)行開始為/usr/bin/podman  運行剛才創(chuàng)建的容器
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target default.target

刪除剛才的容器

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

設置開機自啟

[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模式設置容器和上面這種方式大同小異

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

#需要運行l(wèi)oginctl enable-linger命令,使用戶服務在服務器啟動時自動啟動即可
[containers@serverb ~]$ loginctl enable-linger 

以上就是Podman開機自啟容器實現(xiàn)過程的詳細內(nèi)容,更多關于Podman開機自啟容器的資料請關注腳本之家其它相關文章!

標簽:泰州 銅川 那曲 慶陽 周口 松原 朝陽 蕪湖

巨人網(wǎng)絡通訊聲明:本文標題《Podman開機自啟容器實現(xiàn)過程及與Docker對比》,本文關鍵詞  Podman,開機,自啟,容器,實現(xiàn),;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Podman開機自啟容器實現(xiàn)過程及與Docker對比》相關的同類信息!
  • 本頁收集關于Podman開機自啟容器實現(xiàn)過程及與Docker對比的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    呼玛县| 台南市| 潼关县| 兴城市| 满洲里市| 通城县| 田林县| 泽普县| 昆明市| 博兴县| 苍山县| 苏尼特左旗| 江都市| 曲阳县| 汉寿县| 凌海市| 丹寨县| 中山市| 平罗县| 江西省| 康马县| 凉山| 永春县| 桑植县| 秦安县| 南江县| 新龙县| 武胜县| 乐至县| 中牟县| 乌审旗| 横山县| 马山县| 白沙| 许昌县| 西青区| 孝昌县| 东乌珠穆沁旗| 嘉黎县| 北京市| 论坛|