关于nginx:如何快速建立一个podman环境

2次阅读

共计 2833 个字符,预计需要花费 8 分钟才能阅读完成。

本文介绍如何装置 podman,并创立 podman 容器环境 Centos8 装置 podmanPodman 是一个容器环境,首先在主机上安装 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.conf
user.max_user_namespaces = 28633
上面创立一个 podman 容器来看一下吧,上面应用的是 RHEL 的 UBI 镜像:[root@localhost ~]# podman run ubi8/ubi cat /etc/os-release
Resolved “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 signatures
Checking if image destination supports signatures
Copying blob ce3c6836540f done
Copying blob 63f9f4c31162 done
Copying config cc06568478 done
Writing manifest to image destination
Storing signatures
NAME=”Red Hat Enterprise Linux”
VERSION=”8.5 (Ootpa)”
ID=”rhel”
ID_LIKE=”fedora”
VERSION_ID=”8.5″
PLATFORM_ID=”platform:el8″
PRETTY_NAME=”Red Hat Enterprise Linux 8.5 (Ootpa)”
ANSI_COLOR=”0;31″
CPE_NAME=”cpe:/o:redhat:enterprise_linux:8::baseos”
HOME_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 8″
REDHAT_BUGZILLA_PRODUCT_VERSION=8.5
REDHAT_SUPPORT_PRODUCT=”Red Hat Enterprise Linux”
REDHAT_SUPPORT_PRODUCT_VERSION=”8.5″

创立 Dockerfile 当初能够创立一个 Dockerfile 来指定如何构建新的镜像。首先须要为 Dockerfile 文件创建一个目录:[root@localhost ~]# mkdir ~/myc
[root@localhost ~]# cd ~/myc
创立一个文件 Dockerfile 文件,来建设一个新镜像:[root@localhost myc]# vim Dockerfile

FROM ubi8/ubi:latest
RUN 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-nano
STEP 1/2: FROM ubi8/ubi:latest
STEP 2/2: RUN dnf install -y nano
Updating 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 /]# ls
bin dev home lib64 media opt root sbin sys usr
boot 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 /]# exit
exit
[root@localhost ~]# cat /pod_data/msg.txt
hello podman

能够看到目录绑定之后,在容器中写入数据,退出容器,在本机的 /pod_data 能够看到写入的内容。总结本文介绍如何装置 podman,并创立 podman 容器

正文完
 0