- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Podman开机自启容器实现过程及与Docker对比由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
podman之前是CRI-O项目的一部分,后被分离成独立的项目libpod,libpod是一个创建容器pod的工具和库,podman是个无守护程序容器引擎,以root用户或无根模式运行,简而言之podman提供了一个docker-CLI的命令行,管理着容器 。
docker劣势一:
docker大家都知道,其守护程序在多个核心上占用差不多高达100%cpu资源,采用C/S模型 。
podman优势一:
podman不需要守护进程,不需要root权限组,而且利用着用户命名空间(namespace)模拟容器中的root运行,采用fork/exec模型.
fork/exec模型相比C/S模型优势:
docker的功能大部分podman都是兼容的,也可以使用别名(alias)来写成docker的命令 。
/usr/lib/systemd/user:优先级最低,会被优先级高的同名 unit 覆盖 ~/.local/share/systemd/user 。
/etc/systemd/user:全局共享的用户级 unit[s] 。
~/.config/systemd/user:优先级最高 。
1
2
3
|
#默认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
#基于修改的容器创建新的容器
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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#准备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 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容器,查看服务状态 。
1
2
3
|
[root@podman ~]
# podman exec -it web bash
root@
3528e6d5148b
:
/
# service nginx status
[ ok ] nginx
is
running.
#运行中
|
修改容器业务内容 。
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#修改宿主机/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
#进入容器查看内容是否修改
[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
#或强制删除运行中的容器
[root@podman ~]
# podman rm -f web
3528e6d5148bcf980f0df5708a82419d3485a33d1d16d722db3e880cc103cd2c
|
1
2
|
[root@podman ~]# podman run --name web -d -p 8080:80 -v /opt/webhtml:/usr/shar/nginx/html nginx
910db3ab6bd1ef18e5fd0afe1844912f0b89334b7b8ab758353a948a1b55282a
|
基于web容器,在优先级一般的/etc/systemd/system内 。
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文件,而不是打印到标准输出}
-
-
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
|
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自动生成
# 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.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
#执行开始为/usr/bin/podman 运行刚才创建的容器
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
|
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模式设置容器和上面这种方式大同小异 。
使用systemctl命令带上 --user 即可 。
1
2
|
#需要运行loginctl enable-linger命令,使用户服务在服务器启动时自动启动即可
[containers@serverb ~]$ loginctl enable
-
linger
|
以上就是Podman开机自启容器实现过程的详细内容,更多关于Podman开机自启容器的资料请关注我其它相关文章! 。
原文链接:https://blog.csdn.net/qq_47945825/article/details/119754888 。
最后此篇关于Podman开机自启容器实现过程及与Docker对比的文章就讲到这里了,如果你想了解更多关于Podman开机自启容器实现过程及与Docker对比的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
这是我想做的 1 - 点击提交 2 - 隐藏 DIV 容器 1 3 - 显示 DIV 容器 2 4 - 将“PricingDisclaimer.php”中找到的所有 DIV 加载到 Div 容器 2
我有一个 ios 应用程序,它使用 iCloudcontainer 来保存用户的一些数据,例如用户的“到期日期”。我要用不同的方式创建应用程序的副本开发者账号。我要将用户从第一个应用程序迁移到第二个应
这是场景。 我有三个容器。 Container1、container2 和 container3(基于 Ubuntu 的镜像),其中 container2 充当容器 1 和容器 2 之间的路由器。 我
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我正在改造管道以使用声明式管道方法,以便我能够 to use Docker images在每个阶段。 目前我有以下工作代码,它执行连接到在 Docker 容器中运行的数据库的集成测试。 node {
我正在开发一个需要尽可能简单地为最终用户安装的应用程序。虽然最终用户可能是经验丰富的 Linux 用户(或销售工程师),但他们对 Tomcat、Jetty 等并不真正了解,我认为他们也不应该了解。 所
我从gvisor-containerd-shim(Shim V1)移到了containerd-shim-runsc-v1(Shim V2)。在使用gvisor-containerd-shim的情况下,
假设我们只在某些开发阶段很少需要这样做(冒烟测试几个 api 调用),让项目 Bar 中的 dockerized web 服务访问 Project Foo 中的 dockerized web 服务的最
各位,我的操作系统是 Windows 10,运行的是 Docker 版本 17.06.0-ce-win19。我在 Windows 容器中运行 SQL Server Express,并且希望将 SQL
谁能告诉我,为什么我们不能在 Azure 存储中的容器内创建容器?还有什么方法可以处理,我们需要在 azure 存储中创建目录层次结构? 最佳答案 您无法在容器中创建容器,因为 Windows Azu
#include template struct Row { Row() { puts("Row default"); } Row(const Row& other) { puts
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
RDF容器用于描述一组事物 例如,把一本书的所有作者列在一起 RDF容器有三种类型: <Bag> <Seq> <Alt> <rdf:
编辑:从到目前为止添加的答案和评论看来,我没有正确解释我想要什么。下面是一个例子: // type not supporting any type of comparison [] [] type b
我正在测试 spatie 的异步项目。我创建了一个这样的任务。 use Spatie\Async\Task; class ServiceTask extends Task { protecte
我想使用 Azure Blob 存储来上传和下载文档。有一些公司可以上传和下载他们的文档。我想保证这些文件的安全。这意味着公司只能看到他们的文件。不是别人的。 我可以在 blob 容器中创建多个文件夹
我正在尝试与 Azure 中的容器实例进行远程交互。我已执行以下步骤: 已在本地注册表中加载本地镜像 docker load -i ima.tar 登录远程 ACR docker登录--用户名--密码
我正在研究http://progrium.viewdocs.io/dokku/process-management/,并试图弄清楚如何从单个项目中运行多个服务。 我有一个Dockerfile的仓库:
我有一个想要容器化的单体应用程序。文件夹结构是这样的: --app | |-file.py <-has a variable foo that is passed in --configs
我正在学习 Docker,并且一直在为 Ubuntu 容器制作 Dockerfile。 我的问题是我不断获取不同容器之间的持久信息。我已经退出,移除了容器,然后移除了它的图像。在对 Dockerfil
我是一名优秀的程序员,十分优秀!