环 境
centos8
安装podman
podman 是一个容器环境,首先在主机上安装 podman。执行下面命令来安装podman:
[root@localhost ~]# yum -y install podman 然后修改一下用户命名空间的大小:[root@localhost ~]# echo user.max_user_namespaces=28633 >> /etc/sysctl.d/userns.conf[root@localhost ~]# sysctl -p /etc/sysctl.d/userns.confuser.max_user_namespaces = 28633下面创建一个podman容器来看一下吧,下面使用的是rhel的ubi镜像:[root@localhost ~]# podman run ubi8/ubi cat /etc/os-releaseresolved ubi8/ubi as an alias (/etc/containers/registries.conf.d/001-rhel-shortnames.conf)trying to pull registry.access.redhat.com/ubi8/ubi:latest...getting image source signatureschecking if image destination supports signaturescopying blob ce3c6836540f done copying blob 63f9f4c31162 done copying config cc06568478 done writing manifest to image destinationstoring signaturesname=red hat enterprise linuxversion=8.5 (ootpa)id=rhelid_like=fedoraversion_id=8.5platform_id=platform:el8pretty_name=red hat enterprise linux 8.5 (ootpa)ansi_color=0;31cpe_name=cpe:/oenterprise_linux:baseoshome_url=https://www.redhat.com/documentation_url=https://access.redhat.com/documentation/red_hat_enterprise_linux/8/bug_report_url=https://bugzilla.redhat.com/redhat_bugzilla_product=red hat enterprise linux 8redhat_bugzilla_product_version=8.5redhat_support_product=red hat enterprise linuxredhat_support_product_version=8.5
创建dockerfile
现在可以创建一个 dockerfile 来指定如何构建新的镜像。首先需要为 dockerfile 文件创建一个目录:
[root@localhost ~]# mkdir ~/myc[root@localhost ~]# cd ~/myc 创建一个文件dockerfile文件,来建立一个新镜像:[root@localhost myc]# vim dockerfilefrom ubi8/ubi:latestrun dnf install -y nano
开始使用podman build来创建容器:
[root@localhost myc]# podman build -f dockerfile -t ubi-with-nano[root@localhost myc]# podman build -f dockerfile -t ubi-with-nanostep 1/2: from ubi8/ubi:lateststep 2/2: run dnf install -y nanoupdating subscription management repositories.unable to read consumer identity...
使用podman images来确认是否创建新镜像:
[root@localhost myc]# podman images
现在你可以运行容器了,检查nano编辑器是否可用:
[root@localhost myc]# podman run localhost/ubi-with-nano /usr/bin/which nano/usr/bin/nano 通过查看nano执行文件的位置,来检查是否安装。 nano 现在已安装在你的自定义容器中。还可以交互式的运行容器:[root@localhost myc]# podman run -it localhost/ubi-with-nano /bin/bash[root@d1f0e46f2b6d /]# lsbin dev home lib64 media opt root sbin sys usrboot etc lib lost+found mnt proc run srv tmp var[root@d1f0e46f2b6d /]#
在容器中运行exit来退出容器。 可以使用podman ps来查看运行的容器,如果需要查看以停止的容器,可以添加-a选项:
[root@localhost myc]# podman ps [root@localhost myc]# podman ps -a
存 储
经常让新用户感到困惑的一件事是它们的短暂性。例如进入容器里创建的文件,退出之后,再次进入发现文件没有了。下面我们将容器中需要存储永久性文件的文件夹挂载到系统的某个文件夹中。下面在本机创建一个存储位置:
[root@localhost ~]# mkdir /pod_data 然后使用您的存储目录作为一些相关的挂载点来启动容器。此示例将本地目录/pod_data绑定到容器中名为/storage 的位置,必须在目录位置附加 :z,以便 selinux 可以在主机和 podman 之间转换上下文。[root@localhost ~]# podman run -it --volume /pod_data:/storage:z localhost/ubi-with-nano[root@d590bc344b76 /]# echo hello podman >> /storage/msg.txt[root@d590bc344b76 /]# exitexit[root@localhost ~]# cat /pod_data/msg.txt hello podman
可以看到目录绑定之后,在容器中写入数据,退出容器,在本机的/pod_data可以看到写入的内容。
10分钟学会使用Loki日志聚合系统
Yole:先进封装已成为半导体创新的关键
设计数字无线电接收器的基础知识
详解pcb走线电流
分立功率器件知识分享
如何安装podman并创建podman容器
紫光同日购入中芯、联想股份收盘暴涨逾55.73% 创52周新高
品佳推出NXP Smart Audio音频芯片TFA9890/TFA9897系列
24000V高压电的等离子剑
全新的工艺型PLC S7-1500T常见故障集合
大唐电信FPGA/CPLD数字电路设计经验分享(1)
3d光学轮廓仪基本原理和测试步骤
一招“欲擒故纵”苹果成功将英特尔基带芯片业务收购
科技重塑商业模式,数字化时代的地产营销
云原生和容器间存在怎样的关系
澳洲南部政府联合德国制造商sonnen为188个因火灾失去房屋的人免费提供储能系统
下一站数据中心的主流:200G/400G光模块
ALVA Systems连续两年在中国工业互联网大赛中获奖
smt贴片工厂ICT测试的一般和特殊功能介绍
友尚推出三种不同形态的可穿戴设备应用解决方案