《OpenShift 4.x HOL教程汇总》
已在 RHEL 8.4 上验证

文章目录

  • 构建定制的HTTP容器
    • 构建定制容器
    • 生成systemd服务
    • 测试
  • 参考

构建定制的HTTP容器

构建定制容器

  1. 安装软件。
$ yum install -y buildah podman skopeo
  1. 下载基础镜像。
$ buildah from registry.access.redhat.com/ubi8/ubi:latest
Getting image source signatures
Checking if image destination supports signatures
Copying blob f0ae454850a7 skipped: already exists
Copying blob 053724d29990 [--------------------------------------] 0.0b / 0.0b
Copying config 272209ff0a done
Writing manifest to image destination
Storing signatures
ubi-working-container$ buildah containers
CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
ac89c406967f     *     272209ff0ae5 registry.access.redhat.com/ub... ubi-working-container
  1. 先删除本地的httpd服务,然后在本地容器上安装httpd。
$ yum erase -y httpd
$ buildah run ubi-working-container -- yum -y install httpd
Updating Subscription Management repositories.
Unable to read consumer identity
Subscription Manager is operating in container mode.This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.Red Hat Universal Base Image 8 (RPMs) - BaseOS                                                                                           934 kB/s | 786 kB     00:00
Red Hat Universal Base Image 8 (RPMs) - AppStream                                                                                        402 kB/s | 2.4 MB     00:06
Red Hat Universal Base Image 8 (RPMs) - CodeReady Builder                                                                                 13 kB/s |  15 kB     00:01
Last metadata expiration check: 0:00:01 ago on Mon Jun 14 02:08:38 2021.
Dependencies resolved.
=========================================================================================================================================================================Package                                Architecture               Version                                                     Repository                           Size
=========================================================================================================================================================================
Installing:httpd                                  x86_64                     2.4.37-39.module+el8.4.0+9658+b87b2deb                      ubi-8-appstream                     1.4 M
Installing dependencies:apr                                    x86_64                     1.6.3-11.el8                                                ubi-8-appstream                     125 kapr-util                               x86_64                     1.6.1-6.el8                                                 ubi-8-appstream                     105 khttpd-filesystem                       noarch                     2.4.37-39.module+el8.4.0+9658+b87b2deb                      ubi-8-appstream                      38 khttpd-tools                            x86_64                     2.4.37-39.module+el8.4.0+9658+b87b2deb                      ubi-8-appstream                     106 kmailcap                                noarch                     2.1.48-3.el8                                                ubi-8-baseos                         39 kmod_http2                              x86_64                     1.15.7-3.module+el8.4.0+8625+d397f3da                       ubi-8-appstream                     154 kredhat-logos-httpd                     noarch                     84.4-1.el8                                                  ubi-8-baseos                         29 k
Installing weak dependencies:apr-util-bdb                           x86_64                     1.6.1-6.el8                                                 ubi-8-appstream                      25 kapr-util-openssl                       x86_64                     1.6.1-6.el8                                                 ubi-8-appstream                      27 k
Enabling module streams:httpd                                                             2.4Transaction Summary
=========================================================================================================================================================================
Install  10 PackagesTotal download size: 2.0 M
Installed size: 5.4 M
Downloading Packages:
(1/10): redhat-logos-httpd-84.4-1.el8.noarch.rpm                                                                                         461 kB/s |  29 kB     00:00
(2/10): mailcap-2.1.48-3.el8.noarch.rpm                                                                                                  558 kB/s |  39 kB     00:00
(3/10): httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch.rpm                                                               461 kB/s |  38 kB     00:00
(4/10): apr-util-1.6.1-6.el8.x86_64.rpm                                                                                                  2.7 MB/s | 105 kB     00:00
(5/10): apr-util-openssl-1.6.1-6.el8.x86_64.rpm                                                                                          918 kB/s |  27 kB     00:00
(6/10): httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm                                                                    2.3 MB/s | 106 kB     00:00
(7/10): apr-1.6.3-11.el8.x86_64.rpm                                                                                                      2.7 MB/s | 125 kB     00:00
(8/10): apr-util-bdb-1.6.1-6.el8.x86_64.rpm                                                                                              665 kB/s |  25 kB     00:00
(9/10): mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64.rpm                                                                       2.0 MB/s | 154 kB     00:00
(10/10): httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm                                                                         4.3 MB/s | 1.4 MB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    4.5 MB/s | 2.0 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transactionPreparing        :                                                                                                                                                 1/1Installing       : apr-1.6.3-11.el8.x86_64                                                                                                                        1/10Running scriptlet: apr-1.6.3-11.el8.x86_64                                                                                                                        1/10Installing       : apr-util-openssl-1.6.1-6.el8.x86_64                                                                                                            2/10Installing       : apr-util-bdb-1.6.1-6.el8.x86_64                                                                                                                3/10Installing       : apr-util-1.6.1-6.el8.x86_64                                                                                                                    4/10Running scriptlet: apr-util-1.6.1-6.el8.x86_64                                                                                                                    4/10Installing       : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                                                      5/10Running scriptlet: httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                                                                 6/10Installing       : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                                                                 6/10Installing       : mailcap-2.1.48-3.el8.noarch                                                                                                                    7/10Installing       : redhat-logos-httpd-84.4-1.el8.noarch                                                                                                           8/10Installing       : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                                                                                         9/10Installing       : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                                                           10/10Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                                                           10/10Verifying        : redhat-logos-httpd-84.4-1.el8.noarch                                                                                                           1/10Verifying        : mailcap-2.1.48-3.el8.noarch                                                                                                                    2/10Verifying        : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch                                                                                 3/10Verifying        : apr-util-1.6.1-6.el8.x86_64                                                                                                                    4/10Verifying        : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                                                      5/10Verifying        : apr-util-openssl-1.6.1-6.el8.x86_64                                                                                                            6/10Verifying        : apr-1.6.3-11.el8.x86_64                                                                                                                        7/10Verifying        : apr-util-bdb-1.6.1-6.el8.x86_64                                                                                                                8/10Verifying        : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                                                                                            9/10Verifying        : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                                                                                        10/10
Installed products updated.Installed:apr-1.6.3-11.el8.x86_64                                                          apr-util-1.6.1-6.el8.x86_64apr-util-bdb-1.6.1-6.el8.x86_64                                                  apr-util-openssl-1.6.1-6.el8.x86_64httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                              httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarchhttpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64                        mailcap-2.1.48-3.el8.noarchmod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64                           redhat-logos-httpd-84.4-1.el8.noarchComplete!
  1. 创建http缺省页面并复制到容器中。
$ echo 'Welcome to the RHEL8 workshop!' > index.html
$ buildah copy ubi-working-container index.html /var/www/html/index.html
609feef15d5c341cebe85f9777cdef5e3674ee98476f14549c2b006bc7e60869
  1. 为运行在容器中的httpd服务设置“-D FOREGROUN”和运行端口。
$ buildah config --cmd "/usr/sbin/httpd -D FOREGROUND" ubi-working-container
$ buildah config --port 80 ubi-working-container
  1. 构建容器。
$ buildah commit ubi-working-container httpd
Getting image source signatures
Copying blob 1a6543399d61 skipped: already exists
Copying blob f0a77c369efd skipped: already exists
Copying blob 88f428e6d999 done
Copying config 6b4dbc4e23 done
Writing manifest to image destination
Storing signatures
6b4dbc4e23024eb746da45496084cfe92f6d07ca02d7787d3c27221674bcddd7
  1. 查看并运行容器,“localhost/httpd”为新构建的容器。
$ podman images
REPOSITORY                             TAG      IMAGE ID      CREATED             SIZE
localhost/httpd                        latest   6b4dbc4e2302  About a minute ago  262 MB
registry.access.redhat.com/ubi8/ubi    latest   272209ff0ae5  11 days ago         234 MB$ podman run -d -p 8080:80 httpd
98d25b529b44aa778b5691944616aab57e399f6d7a2b7b782d74e29c6083db30$ podman ps
CONTAINER ID  IMAGE                                         COMMAND               CREATED        STATUS            PORTS                                             NAMES
98d25b529b44  localhost/httpd:latest                        /usr/sbin/httpd -...  7 seconds ago  Up 6 seconds ago  0.0.0.0:8080->80/tcp                              dazzling_rosalind$ podman top -l
USER     PID   PPID   %CPU    ELAPSED         TTY   TIME   COMMAND
root     1     0      0.000   13.528590572s   ?     0s     /usr/sbin/httpd -D FOREGROUND
apache   6     1      0.000   13.528951222s   ?     0s     /usr/sbin/httpd -D FOREGROUND
apache   7     1      0.000   13.530009913s   ?     0s     /usr/sbin/httpd -D FOREGROUND
apache   8     1      0.000   13.530228674s   ?     0s     /usr/sbin/httpd -D FOREGROUND
apache   9     1      0.000   13.5303452s     ?     0s     /usr/sbin/httpd -D FOREGROUND$ curl -s http://localhost:8080
Welcome to the RHEL8 workshop!$ podman stop -a
$ podman ps -l
CONTAINER ID  IMAGE                   COMMAND               CREATED         STATUS                    PORTS                 NAMES
98d25b529b44  localhost/httpd:latest  /usr/sbin/httpd -...  47 seconds ago  Exited (0) 6 seconds ago  0.0.0.0:8080->80/tcp  dazzling_rosalind$ podman stop 98d25b529b44
98d25b529b44aa778b5691944616aab57e399f6d7a2b7b782d74e29c6083db30

生成systemd服务

  1. 确认已关闭系统的“fapolicyd”服务。
$ systemctl disable --now fapolicyd.service
Failed to disable unit: Unit file fapolicyd.service does not exist.
  1. 查看本地容器详细信息。
$ skopeo inspect containers-storage:localhost/httpd
INFO[0000] Not using native diff for overlay, this may cause degraded performance for building images: kernel has CONFIG_OVERLAY_FS_REDIRECT_DIR enabled
{"Name": "localhost/httpd","Digest": "sha256:0ddbdb3d09e681e6918ffada4048ceb8aafae019e046036908438bd2cda8e81e","RepoTags": [],"Created": "2021-06-14T02:09:43.784286286Z","DockerVersion": "","Labels": {"architecture": "x86_64","build-date": "2021-06-02T19:27:01.978498","com.redhat.build-host": "cpt-1005.osbs.prod.upshift.rdu2.redhat.com","com.redhat.component": "ubi8-container","com.redhat.license_terms": "https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI","description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.","distribution-scope": "public","io.buildah.version": "1.19.8","io.k8s.description": "The Universal Base Image is designed and engineered to be the base layer for all of your containerized applications, middleware and utilities. This base image is freely redistributable, but Red Hat only supports Red Hat technologies through subscriptions for Red Hat products. This image is maintained by Red Hat and updated regularly.","io.k8s.display-name": "Red Hat Universal Base Image 8","io.openshift.expose-services": "","io.openshift.tags": "base rhel8","maintainer": "Red Hat, Inc.","name": "ubi8","release": "203.1622660121","summary": "Provides the latest release of Red Hat Universal Base Image 8.","url": "https://access.redhat.com/containers/#/registry.access.redhat.com/ubi8/images/8.4-203.1622660121","vcs-ref": "ed5adf70c28eb951940c72f4173fa32c4bca2165","vcs-type": "git","vendor": "Red Hat, Inc.","version": "8.4"},"Architecture": "amd64","Os": "linux","Layers": ["sha256:1a6543399d619ac51e7b928aa443dac16e52e28522e8e5d2232ee2360569f2c2","sha256:f0a77c369efd5e6bde23cd1e9a6472b2781ea306e9872ce4c3c334fc55dd7481","sha256:88f428e6d99908614a1d4ea784cc28caaf4c12cc93b03491b30150140b69a1c3"],"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","container=oci"]
}
  1. 查看本地容器详细信息。
$ podman create -p 80:80 --name web httpd
0346dec890fb13b1aff375659b9deb3f345453165eabebf80832e11ab2457c04
  1. 根据运行的容器生成systemd的配置文件。
$ podman generate systemd --name web -f
/root/container-web.service
  1. 查看生成的systemd配置文件。
$ cat container-web.service
# container-web.service
# autogenerated by Podman 3.0.2-dev
# Mon Jun 14 10:19:39 CST 2021[Unit]
Description=Podman container-web.service
Documentation=man:podman-generate-systemd(1)
Wants=network.target
After=network-online.target[Service]
Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
TimeoutStopSec=70
ExecStart=/usr/bin/podman start web
ExecStop=/usr/bin/podman stop -t 10 web
ExecStopPost=/usr/bin/podman stop -t 10 web
PIDFile=/run/containers/storage/overlay-containers/0346dec890fb13b1aff375659b9deb3f345453165eabebf80832e11ab2457c04/userdata/conmon.pid
Type=forking[Install]
WantedBy=multi-user.target default.target
  1. 根据systemd配置文件创建“container-web”服务。
$ cp container-web.service /etc/systemd/system/
$ systemctl daemon-reload
$ 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.

测试

  1. 确认容器已经运行并可以访问。
$ podman ps
CONTAINER ID  IMAGE                   COMMAND               CREATED             STATUS            PORTS               NAMES
0346dec890fb  localhost/httpd:latest  /usr/sbin/httpd -...  About a minute ago  Up 6 seconds ago  0.0.0.0:80->80/tcp  web
$ curl -s http://localhost
Welcome to the RHEL8 workshop!
  1. 重启系统。由于运行在容器中的httpd服务会作为systemd服务自动启动,因此可以访问到httpd服务。
$ curl -s http://localhost
Welcome to the RHEL8 workshop!

参考

http://redhatgov.io/workshops/rhel_8/exercise1.8/

RHEL 8 - 用podman/buildah/skopeo构建systemd级别运行容器相关推荐

  1. 在openEuler 21.9安装自带的容器软件Docker、podman、skopeo

    openEuler 21.9上的Docker.podman.Skopeo版本都偏低. 此外没有自带buildah和cri-o. 不知道下一个版本情况会不会好点. [root@openeuler iso ...

  2. docker新建Linux虚拟机,RHEL/CentOS 7下创建你的第一个Docker容器

    Docker容器人气一直在增长.他们现在正在快速采用,正在取代虚拟机,特别是在应用程序开发方面. 在本教程中,我们将讨论Docker容器的内容,并将学习在RHEL/CentOS 7上安装它的过程. D ...

  3. 在生产环境中,阿里云如何构建高性能云原生容器网络?(含 PPT 下载)

    作者 | 溪恒  阿里云技术专家 直播完整视频回顾:https://www.bilibili.com/video/BV1nC4y1x7mt/ 关注"阿里巴巴云原生"公众号,后台回复 ...

  4. 如何构建尽可能小的容器镜像?

    关注我们获得更多内容 这是Google Developer Advocate Sandeep Dinesh 关于如何充分利用Kubernetes环境的七部分视频和博客系列的第一部分. 主要讲保持容器镜 ...

  5. 阿里云构建千万级别架构演变之路

    阿里云构建千万级别架构演变之路 摘要: 随着云计算的到来,当前已经从IT时代向DT时代开始转型.在云端如何构建千万级架构,本文主要结合阿里云最佳实践经验,向大家分享如何从一个小型网站逐步演变到千万级架 ...

  6. 使用python构建向量空间_使用Docker构建Python数据科学容器

    人工智能(AI)和机器学习(ML)最近真的火了,并驱动了从自动驾驶汽车到药物发现等等应用领域的快速发展.AI和ML的前途一片光明. 另一方面,Docker通过引入临时轻量级容器彻底改变了计算世界.通过 ...

  7. 使用docker构建jenkins镜像并运行容器

    https://my.oschina.net/donhui/blog/470372?p={{currentPage+1}}   摘要: 使用docker构建jenkins镜像并运行容器 目录: 1.基 ...

  8. 【如何构建商业级别聊天系统】 MQTT 篇(五)保活 Keep Alive,请不要让你的 MQTT 服务变成小猪佩奇!

    [如何构建商业级别聊天系统] MQTT 篇(五)保活 Keep Alive,请不要让你的 MQTT 服务变成小猪佩奇! 特关人上人!dying 搁浅 神秘连接 哥哥姐姐弟弟妹妹叔叔阿姨们~ 说点闲话 ...

  9. 2020 OpenInfra Days China :OpenStack+Kubernetes,构建新一代私有云和容器云

    8月16-17日,由OpenStack基金会举办的国内极具影响力的开源盛会2020 OpenInfra Days China在线上召开.本次大会聚焦"智能开源基础设施",围绕人工智 ...

最新文章

  1. 我在大厂,下班了也戴着工牌
  2. systemd设置静态IP
  3. pyinstaller 安装使用方法
  4. spring resource
  5. NUC970开发资源
  6. Codeforces Round #229
  7. 阅读笔记 1 火球 UML大战需求分析
  8. 嵌入式linux配置qt,基于qt的嵌入式Linux开发环境搭建
  9. 获取网络接口信息——ioctl()函数与结构体struct ifreq、 struct ifconf
  10. H3C 路由度量值(Metric)
  11. Java如何封装参数_java规范(一)------方法设计---返回多参数的方法怎么封装
  12. c语言算法课件,《C语言常见算法》PPT课件.ppt
  13. 以太坊源码学习(一)
  14. jenkins 控制台输出中文乱码
  15. 中国废弃电器电子产品回收处理行业发展格局与投资风险可行性报告2022~2027年
  16. 计算机科学第三讲——布尔逻辑和逻辑门
  17. 【科创人独家】军哥手记程军:我的2020,先打个60分吧
  18. 计算机二级考试题库vb知识点,国家计算机二级考试题库 VB上机试题第13套
  19. BlueTooth蓝牙协议规范(四)
  20. 宇宙最强IDE!微软正式宣布 Visual Studio 2019

热门文章

  1. 简述php和web交互过程,PHP与Web页面交互操作实例分析
  2. 计算机系统如何禁止删除文件,电脑禁止安装删除文件 禁止复制电脑文件的方法...
  3. python官网安装程序的功能和特点_python介绍与安装(一)
  4. qmenu点击后不关闭_速腾关闭点火开关后发动机不立即熄火
  5. c55x 汇编语言指令,[转载]关于TMS320C55x的汇编语言中的.sym伪指令
  6. 在优图网,临摹借鉴设计大咖作品|品图标设计:主要趋势
  7. 万圣节魅惑手绘插画素材,没想到你是这样的可爱!
  8. UI设计素材模板|wireframe线框图设计要点
  9. UI设计素材之按钮和选框,悠闲素材帮你轻松搞定设计。
  10. 插画在UI的应用体验,太美好了!这样的模板让你的用户更加喜欢!