红帽通用基础映像(UBI)被设计为在容器中开发的云原生和Web应用程序用例的基础。你可以使用UBI构建一个容器化的应用程序,将其推送到你所选择的注册服务器上,轻松地与他人分享–由于它是可自由再分配的–甚至可以将其部署到非红帽平台。由于它建立在红帽企业Linux上,UBI是一个可靠、安全和高性能的平台。
UBI是红帽的容器就绪的操作系统映像,允许你建立更小的映像,用于基于容器的系统。目前有如下4类UBI镜像:
$ yum install -y podman buildah
$ buildah from registry.access.redhat.com/ubi8/ubi
Getting image source signatures
Copying blob e45283d00526 done
Copying blob c51b1b38edbb done
Copying config 18b22de14a done
Writing manifest to image destination
Storing signatures
ubi-working-container
$ buildah images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/ubi8/ubi latest 18b22de14a6f 7 days ago 234 MB
$ buildah containers
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
ede6c61d04ca * 18b22de14a6f registry.access.redhat.com/ub... ubi-working-container
说明:“buildah containers”等同于“buildah ps”或“buildah list”。
5. 查看运行的容器详细信息
$ buildah inspect ede6c61d04ca
{
"Type": "buildah 0.0.1",
"FromImage": "registry.access.redhat.com/ubi8/ubi:latest",
"FromImageID": "18b22de14a6f0b26dd2cffb73a1f5980072ce4e81af759d83d551520e67d483b",
"FromImageDigest": "sha256:557f9b9c5508eaf4f1b6b8420df06a83a96f11a9a19b92f28e6b771186a558ca",
。。。
$ buildah run ubi-working-container cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)
$ buildah run ubi-working-container cat /etc/yum.repos.d/ubi.repo
[ubi-8-baseos]
name = Red Hat Universal Base Image 8 (RPMs) - BaseOS
baseurl = https://cdn-ubi.redhat.com/content/public/ubi/dist/ubi8/8/$basearch/baseos/os
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
gpgcheck = 1
。。。(省略)
$ buildah run ubi-working-container -- yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
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 Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 39 MB/s | 33 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 42 MB/s | 30 MB 00:00
Red Hat Universal Base Image 8 (RPMs) - BaseOS 4.4 MB/s | 786 kB 00:00
Red Hat Universal Base Image 8 (RPMs) - AppStream 39 MB/s | 7.4 MB 00:00
Red Hat Universal Base Image 8 (RPMs) - CodeReady Builder 183 kB/s | 15 kB 00:00
epel-release-latest-8.noarch.rpm 51 kB/s | 22 kB 00:00
Dependencies resolved.
===========================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================
Installing:
epel-release noarch 8-10.el8 @commandline 22 k
Transaction Summary
===========================================================================================================================================
Install 1 Package
Total size: 22 k
Installed size: 32 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : epel-release-8-10.el8.noarch 1/1
Running scriptlet: epel-release-8-10.el8.noarch 1/1
Verifying : epel-release-8-10.el8.noarch 1/1
Installed products updated.
Installed:
epel-release-8-10.el8.noarch
Complete!
$ rpm -q epel-release
package epel-release is not installed
$ buildah run ubi-working-container -- yum -y install moon-buggy
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.
Extra Packages for Enterprise Linux Modular 8 - x86_64 1.0 MB/s | 610 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 13 MB/s | 9.4 MB 00:00
Dependencies resolved.
===========================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================
Installing:
moon-buggy x86_64 1.0.51-25.el8 epel 81 k
Installing dependencies:
alsa-lib x86_64 1.2.4-5.el8 rhel-8-for-x86_64-appstream-rpms 471 k
audiofile x86_64 1:0.3.6-23.el8 epel 141 k
esound-libs x86_64 1:0.2.41-22.el8 epel 84 k
flac-libs x86_64 1.3.2-9.el8 rhel-8-for-x86_64-appstream-rpms 217 k
libogg x86_64 2:1.3.2-10.el8 rhel-8-for-x86_64-appstream-rpms 31 k
Transaction Summary
===========================================================================================================================================
Install 6 Packages
Total download size: 1.0 M
Installed size: 2.7 M
Downloading Packages:
(1/6): audiofile-0.3.6-23.el8.x86_64.rpm 2.3 MB/s | 141 kB 00:00
(2/6): esound-libs-0.2.41-22.el8.x86_64.rpm 521 kB/s | 84 kB 00:00
(3/6): moon-buggy-1.0.51-25.el8.x86_64.rpm 277 kB/s | 81 kB 00:00
(4/6): libogg-1.3.2-10.el8.x86_64.rpm 119 kB/s | 31 kB 00:00
(5/6): flac-libs-1.3.2-9.el8.x86_64.rpm 586 kB/s | 217 kB 00:00
(6/6): alsa-lib-1.2.4-5.el8.x86_64.rpm 1.3 MB/s | 471 kB 00:00
-------------------------------------------------------------------------------------------------------------------------------------------
Total 905 kB/s | 1.0 MB 00:01
warning: /var/cache/dnf/epel-fafd94c310c51e1e/packages/audiofile-0.3.6-23.el8.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 2f86d6a1: NOKEY
Extra Packages for Enterprise Linux 8 - x86_64 1.6 MB/s | 1.6 kB 00:00
Importing GPG key 0x2F86D6A1:
Userid : "Fedora EPEL (8) <epel@fedoraproject.org>"
Fingerprint: 94E2 79EB 8D8F 25B2 1810 ADF1 21EA 45AB 2F86 D6A1
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : alsa-lib-1.2.4-5.el8.x86_64 1/6
Running scriptlet: alsa-lib-1.2.4-5.el8.x86_64 1/6
Installing : libogg-2:1.3.2-10.el8.x86_64 2/6
Installing : flac-libs-1.3.2-9.el8.x86_64 3/6
Installing : audiofile-1:0.3.6-23.el8.x86_64 4/6
Installing : esound-libs-1:0.2.41-22.el8.x86_64 5/6
Installing : moon-buggy-1.0.51-25.el8.x86_64 6/6
Running scriptlet: moon-buggy-1.0.51-25.el8.x86_64 6/6
Verifying : audiofile-1:0.3.6-23.el8.x86_64 1/6
Verifying : esound-libs-1:0.2.41-22.el8.x86_64 2/6
Verifying : moon-buggy-1.0.51-25.el8.x86_64 3/6
Verifying : flac-libs-1.3.2-9.el8.x86_64 4/6
Verifying : libogg-2:1.3.2-10.el8.x86_64 5/6
Verifying : alsa-lib-1.2.4-5.el8.x86_64 6/6
Installed products updated.
Installed:
alsa-lib-1.2.4-5.el8.x86_64 audiofile-1:0.3.6-23.el8.x86_64 esound-libs-1:0.2.41-22.el8.x86_64 flac-libs-1.3.2-9.el8.x86_64
libogg-2:1.3.2-10.el8.x86_64 moon-buggy-1.0.51-25.el8.x86_64
Complete!
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.access.redhat.com/ubi8/ubi latest 18b22de14a6f 7 days ago 234 MB
$ buildah commit ubi-working-container moon-buggy
Getting image source signatures
Copying blob baedd15dd07e skipped: already exists
Copying blob 1e05587d4a9f skipped: already exists
Copying blob d487a9463f88 done
Copying config ff5e289069 done
Writing manifest to image destination
Storing signatures
ff5e28906909086dd354be1b0b7d9bff941f0705f1a2ec23c054d6f5dcba3a75
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/moon-buggy latest ff5e28906909 18 seconds ago 418 MB
registry.access.redhat.com/ubi8/ubi latest 18b22de14a6f 7 days ago 234 MB
$ podman run -it moon-buggy /usr/bin/moon-buggy
Moon-Buggy version 1.0.51+esd, Copyright 2004 Jochen Voss <voss@seehuhn.de>
Moon-Buggy comes with ABSOLUTELY NO WARRANTY; for details type 'w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'c' for details.
MM MM OOOOO OOOOO NN N
M M M M O O O O N N N
M M M M O O O O N N N
M M M O O O O N N N
M M O O O O N N N
M M OOOOO OOOOO N NN
BBBBBB U U GGGGG GGGGG Y Y
B B U U G G G G Y Y
BBBBBB U U G G Y Y
B B U U G GGG G GGG Y
B B U U G G G G Y
BBBBBB UUUUU GGGGG GGGGG YY
Omm
(|)-(|)
####################################################################################################
####################################################################################################
y,SPC,RET:start game q,n:quit c:show copyright w:show warranty s:show scores r,C-l:redraw
$ buildah ps --all
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
c8cc546ce9ba * 18b22de14a6f registry.access.redhat.com/ub... ubi-working-container
c9961b90a70e 8050aac88b92 localhost/moon-buggy:latest charming_neumann
$ buildah from registry.access.redhat.com/ubi8/ubi-init
Getting image source signatures
Copying blob c51b1b38edbb done
Copying blob 26cb90e4ae84 done
Copying blob e45283d00526 done
Copying config 9bbdcc2d3f done
Writing manifest to image destination
Storing signatures
ubi-init-working-container
$ buildah run ubi-init-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 Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 26 MB/s | 33 MB 00:01
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 28 MB/s | 30 MB 00:01
Red Hat Universal Base Image 8 (RPMs) - BaseOS 5.4 MB/s | 786 kB 00:00
Red Hat Universal Base Image 8 (RPMs) - AppStream 37 MB/s | 7.4 MB 00:00
Red Hat Universal Base Image 8 (RPMs) - CodeReady Builder 158 kB/s | 15 kB 00:00
Dependencies resolved.
buildah run ubi-init-working-container -- systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
$ cat << EOF > index1.html
index page 1
EOF
$ buildah copy ubi-init-working-container index1.html /var/www/html/index.html
c03382e8c990233b6ac7ccbef803c6556421825e8e400a0dea41826940713ac7
$ buildah config --port 80 --cmd "/usr/sbin/init" ubi-init-working-container
$ buildah commit ubi-init-working-container el-httpd1
Getting image source signatures
Copying blob baedd15dd07e skipped: already exists
Copying blob 1e05587d4a9f skipped: already exists
Copying blob 5f7bc1e8ff4c skipped: already exists
Copying blob 2a8794f0ce87 [--------------------------------------] 0.0b / 0.0b
Copying config 7d309d19db done
Writing manifest to image destination
Storing signatures
7d309d19dbcf443c4840848eaf974b6c9d36b6b816d3aaedaea1698ac2134399
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/el-httpd1 latest 7d309d19dbcf 4 minutes ago 414 MB
registry.access.redhat.com/ubi8/ubi-init latest 9bbdcc2d3f32 7 days ago 251 MB
$ podman run -d -p 80:80 el-httpd1
d36f80196646541f2538a56bcd85fb345314847b900ea6f6b3b0a9035dc69cb6
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d36f80196646 localhost/el-httpd1:latest /usr/sbin/init 29 seconds ago Up 28 seconds ago 0.0.0.0:80->80/tcp trusting_hermann
$ buildah inspect localhost/el-httpd1
{
"Type": "buildah 0.0.1",
"FromImage": "localhost/el-httpd1:latest",
"FromImageID": "7d309d19dbcf443c4840848eaf974b6c9d36b6b816d3aaedaea1698ac2134399",
"FromImageDigest": "sha256:fbfb75636edd40965aaffc07b6627033ee3a3872ebc92d5fdb755e92176ff551",
。。。
$ curl http://localhost
12.停掉所有运行的容器 。
$ podman stop -a
d36f80196646541f2538a56bcd85fb345314847b900ea6f6b3b0a9035dc69cb6
$ buildah from scratch
working-container
$ scratchmnt=$(buildah mount working-container)
$ echo ${scratchmnt}
/var/lib/containers/storage/overlay/f8fa6992ba9d780f45dfa476235d3da5dc98deba7f49cee928b448a7bbfe52b6/merged
$ ls -l ${scratchmnt}
total 0
$ yum install --installroot ${scratchmnt} httpd --releasever 8 --setopt=module_platform_id="platform:el8" -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 2.4 MB/s | 7.0 MB 00:02
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 1.3 MB/s | 3.7 MB 00:02
Red Hat Enterprise Linux 8 for x86_64 - Supplementary (RPMs) 23 kB/s | 78 kB 00:03
Last metadata expiration check: 0:00:01 ago on Fri 17 May 2019 03:41:34 PM EDT.
Dependencies resolved.
====================================================================================================================
Package Arch Version Repository Size
====================================================================================================================
Installing:
httpd x86_64 2.4.37-11.module+el8.0.0+2969+90015743 rhel-8-for-x86_64-appstream-rpms 1.4 M
<< OUTPUT ABRIDGED >>
Complete!
$ chroot ${scratchmnt} systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
$ cat << EOF > index2.html
index page 2
EOF
$ cp index2.html ${scratchmnt}/var/www/html/index.html
$ ls -l ${scratchmnt}
total 12
lrwxrwxrwx. 1 root root 7 Apr 23 2020 bin -> usr/bin
dr-xr-xr-x. 4 root root 30 Jun 3 16:17 boot
drwxr-xr-x. 2 root root 18 Jun 3 16:17 dev
drwxr-xr-x. 53 root root 4096 Jun 3 16:18 etc
drwxr-xr-x. 2 root root 6 Apr 23 2020 home
lrwxrwxrwx. 1 root root 7 Apr 23 2020 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Apr 23 2020 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Apr 23 2020 media
drwxr-xr-x. 2 root root 6 Apr 23 2020 mnt
drwxr-xr-x. 2 root root 6 Apr 23 2020 opt
dr-xr-xr-x. 2 root root 6 Apr 23 2020 proc
dr-xr-x---. 2 root root 6 Apr 23 2020 root
drwxr-xr-x. 13 root root 162 Jun 3 16:18 run
lrwxrwxrwx. 1 root root 8 Apr 23 2020 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Apr 23 2020 srv
dr-xr-xr-x. 2 root root 6 Apr 23 2020 sys
drwxrwxrwt. 2 root root 6 Apr 23 2020 tmp
drwxr-xr-x. 12 root root 144 Jun 3 16:17 usr
drwxr-xr-x. 20 root root 4096 Jun 3 16:18 var
$ buildah unmount working-container
66fa1c4c764491a77cdf7b1b16a646dbf17dbe8925ff9a1b1e8866aad46fd3e8
$ buildah config --port 80 --cmd "/usr/sbin/init" working-container
$ buildah commit working-container el-httpd2
Getting image source signatures
Copying blob 9b095605ad72 done
Copying config 098c1605a7 done
Writing manifest to image destination
Storing signatures
098c1605a7cbe3a1cdd3a0e28fc3a19d996e8fba26656834caf4a30c22f62fd3
$ podman images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/el-httpd2 latest 098c1605a7cb 24 seconds ago 657 MB
localhost/el-httpd1 latest 9c105d0cc696 5 minutes ago 414 MB
registry.access.redhat.com/ubi8/ubi-init latest 9bbdcc2d3f32 7 days ago 251 MB
$ podman run -d -p 80:80 el-httpd2
bb0f61fe23ffc9ea60be24f9c2f09db9b4794a5d60e9f4989663b05fa9edb6f8
$ podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bb0f61fe23ff localhost/el-httpd2:latest /usr/sbin/init 1 second ago Up Less than a second ago 0.0.0.0:80->80/tcp cranky_haslett
$ buildah inspect localhost/el-httpd2
$ curl http://localhost
$ podman stop -a
以下操作需要提前登录OpenShift。
$ oc new-app --context-dir=getting-started --name=quarkus-quickstart registry.access.redhat.com/ubi8/openjdk-11~https://github.com/quarkusio/quarkus-quickstarts.git#1.13.3.Final
$ oc expose svc/quarkus-quickstart
$ export URI="http://$(oc get route | grep quarkus-quickstart | awk '{print $2}')"
$ curl $URI/hello/greeting/quarkus
hello quarkus
https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/8/html-single/building_running_and_managing_containers/index