银河麒麟高级服务器操作系统基础docker镜像封装http和docker端口映射操作
银河麒麟高级服务器操作系统基础docker镜像封装http和docker端口映射操作
- 一、系统环境
- 二、基础信息
- 2.1 docker版本
- 三、具体配置步骤
- 3.1 安装docker 18.09
- 3.1.1 卸载系统自带的docker-runc
- 3.1.2 安装yum源中最新的docker版本
- 3.2 导入测试docker镜像
- 3.3 启动一个容器pod
- 3.4 进入启动的容器安装web服务
- 3.4.1 进入容器
- 3.4.2 安装httpd服务
- 3.4.3 将httpd服务设置开机自启
- 3.5 将启动的pod重新封装成iamges镜像
- 3.5.1 停止pod
- 3.5.2 将pod封装成docker镜像
- 3.6 使用封装好的镜像下发pod并映射端口(8001:80)
- 四、使用curl命令验证
一、系统环境
#本文采用V10SP3-2403服务器版本进行演示
[root@localhost ~]# nkvers
############## Kylin Linux Version #################
Release:
Kylin Linux Advanced Server release V10 (Halberd)
Kernel:
4.19.90-89.19.v2401.ky10.aarch64
Build:
Kylin Linux Advanced Server
release V10 SP3 2403/(Halberd)-aarch64-Build20/20240426
#################################################
二、基础信息
2.1 docker版本
[root@localhost ~]# yum list | grep docker-engine
docker-engine.aarch64 1:18.09.0-261.p05.04.ky10 ks10-adv-updates
三、具体配置步骤
3.1 安装docker 18.09
3.1.1 卸载系统自带的docker-runc
[root@localhost ~]# yum remove docker-runc
Dependencies resolved.
==============================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================
Removing:
docker-runc aarch64 1.0.0.rc3-222.ky10 @anaconda 7.8 M
Removing dependent packages:
podman aarch64 1:0.10.1-8.ky10 @anaconda 26 M
Removing unused dependencies:
conmon aarch64 2:2.0.2-2.ky10 @anaconda 174 k
container-selinux noarch 2:2.138.0-1.p01.ky10 @anaconda 45 k
containernetworking-plugins aarch64 0.8.6-5.gitad10b6f.p01.ky10 @anaconda 56 M
containers-common aarch64 1:1.1.0-9.p01.ky10 @anaconda 15 k
Transaction Summary
==============================================================================================================================================================================================
Remove 6 Packages
Freed space: 91 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: podman-1:0.10.1-8.ky10.aarch64 1/1
Erasing : podman-1:0.10.1-8.ky10.aarch64 1/6
Running scriptlet: podman-1:0.10.1-8.ky10.aarch64 1/6
Erasing : container-selinux-2:2.138.0-1.p01.ky10.noarch 2/6
Running scriptlet: container-selinux-2:2.138.0-1.p01.ky10.noarch 2/6
Erasing : containers-common-1:1.1.0-9.p01.ky10.aarch64 3/6
Erasing : conmon-2:2.0.2-2.ky10.aarch64 4/6
Erasing : containernetworking-plugins-0.8.6-5.gitad10b6f.p01.ky10.aarch64 5/6
Erasing : docker-runc-1.0.0.rc3-222.ky10.aarch64 6/6
Running scriptlet: docker-runc-1.0.0.rc3-222.ky10.aarch64 6/6
Verifying : conmon-2:2.0.2-2.ky10.aarch64 1/6
Verifying : container-selinux-2:2.138.0-1.p01.ky10.noarch 2/6
Verifying : containernetworking-plugins-0.8.6-5.gitad10b6f.p01.ky10.aarch64 3/6
Verifying : containers-common-1:1.1.0-9.p01.ky10.aarch64 4/6
Verifying : docker-runc-1.0.0.rc3-222.ky10.aarch64 5/6
Verifying : podman-1:0.10.1-8.ky10.aarch64 6/6
Removed:
conmon-2:2.0.2-2.ky10.aarch64 container-selinux-2:2.138.0-1.p01.ky10.noarch containernetworking-plugins-0.8.6-5.gitad10b6f.p01.ky10.aarch64
containers-common-1:1.1.0-9.p01.ky10.aarch64 docker-runc-1.0.0.rc3-222.ky10.aarch64 podman-1:0.10.1-8.ky10.aarch64
Complete!
3.1.2 安装yum源中最新的docker版本
[root@localhost ~]# yum install docker -y
Kylin Linux Advanced Server 10 - Os 12 MB/s | 14 MB 00:01
Kylin Linux Advanced Server 10 - Updates 9.8 MB/s | 9.1 MB 00:00
Last metadata expiration check: 0:00:03 ago on 2025年03月28日 星期五 14时16分34秒.
Dependencies resolved.
==============================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================
Installing:
docker-engine aarch64 1:18.09.0-261.p05.04.ky10 ks10-adv-updates 30 M
Transaction Summary
==============================================================================================================================================================================================
Install 1 Package
Total download size: 30 M
Installed size: 145 M
Downloading Packages:
docker-engine-18.09.0-261.p05.04.ky10.aarch64.rpm 11 MB/s | 30 MB 00:02
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 11 MB/s | 30 MB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : docker-engine-1:18.09.0-261.p05.04.ky10.aarch64 1/1
Running scriptlet: docker-engine-1:18.09.0-261.p05.04.ky10.aarch64 1/1
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
Verifying : docker-engine-1:18.09.0-261.p05.04.ky10.aarch64 1/1
Installed:
docker-engine-1:18.09.0-261.p05.04.ky10.aarch64
Complete!
[root@localhost ~]#
3.2 导入测试docker镜像
[root@localhost ~]# docker load -i kylin-server-10-sp1-0518-aarch.tar.xz
d4dda423c77e: Loading layer [==================================================>] 423.5MB/423.5MB
Loaded image: kylin-server-10-sp1-0518-aarch:b20
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kylin-server-10-sp1-0518-aarch b20 df7a9105d15e 3 years ago 411MB
[root@localhost ~]#
3.3 启动一个容器pod
[root@localhost ~]# docker run --privileged=true --name kylin-test1 -it df7a9105d15e /sbin/init
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
395e9257b616 df7a9105d15e "/sbin/init" About a minute ago Up About a minute kylin-test1
3.4 进入启动的容器安装web服务
3.4.1 进入容器
[root@localhost ~]# docker exec --privileged -it 395e9257b616 /bin/bash
3.4.2 安装httpd服务
[root@395e9257b616 /]# yum install httpd -y
Failed to set locale, defaulting to C
Last metadata expiration check: 0:02:10 ago on Fri Mar 28 14:22:57 2025.
Dependencies resolved.
==============================================================================================================================================================================================
Package Architecture Version Repository Size
==============================================================================================================================================================================================
Installing:
httpd aarch64 2.4.43-26.p01.ky10 ks10-adv-updates 1.3 M
Upgrading:
libselinux aarch64 3.1-1.se.05.ky10 ks10-adv-updates 112 k
replacing libselinux-utils.aarch64 2.9-se.06.ky10
python3-libselinux aarch64 3.1-1.se.05.ky10 ks10-adv-updates 156 k
Installing dependencies:
kylin-logos noarch 1.0-6.8.p01.ky10 ks10-adv-os 15 M
apr aarch64 1.7.0-4.ky10 ks10-adv-updates 106 k
apr-util aarch64 1.6.1-15.ky10 ks10-adv-updates 109 k
httpd-filesystem noarch 2.4.43-26.p01.ky10 ks10-adv-updates 13 k
httpd-help noarch 2.4.43-26.p01.ky10 ks10-adv-updates 2.4 M
httpd-tools aarch64 2.4.43-26.p01.ky10 ks10-adv-updates 72 k
mailcap noarch 2.1.49-3.ky10 ks10-adv-updates 32 k
mariadb-connector-c aarch64 3.0.6-8.p01.ky10 ks10-adv-updates 126 k
mod_http2 aarch64 1.15.13-2.ky10 ks10-adv-updates 120 k
Transaction Summary
==============================================================================================================================================================================================
Install 10 Packages
Upgrade 2 Packages
Total download size: 20 M
Downloading Packages:
(1/12): apr-1.7.0-4.ky10.aarch64.rpm 160 kB/s | 106 kB 00:00
(2/12): apr-util-1.6.1-15.ky10.aarch64.rpm 93 kB/s | 109 kB 00:01
(3/12): httpd-filesystem-2.4.43-26.p01.ky10.noarch.rpm 77 kB/s | 13 kB 00:00
(4/12): httpd-2.4.43-26.p01.ky10.aarch64.rpm 1.6 MB/s | 1.3 MB 00:00
(5/12): httpd-help-2.4.43-26.p01.ky10.noarch.rpm 6.3 MB/s | 2.4 MB 00:00
(6/12): httpd-tools-2.4.43-26.p01.ky10.aarch64.rpm 112 kB/s | 72 kB 00:00
(7/12): mailcap-2.1.49-3.ky10.noarch.rpm 81 kB/s | 32 kB 00:00
(8/12): mod_http2-1.15.13-2.ky10.aarch64.rpm 775 kB/s | 120 kB 00:00
(9/12): mariadb-connector-c-3.0.6-8.p01.ky10.aarch64.rpm 638 kB/s | 126 kB 00:00
(10/12): libselinux-3.1-1.se.05.ky10.aarch64.rpm 1.0 MB/s | 112 kB 00:00
(11/12): python3-libselinux-3.1-1.se.05.ky10.aarch64.rpm 509 kB/s | 156 kB 00:00
(12/12): kylin-logos-1.0-6.8.p01.ky10.noarch.rpm 4.3 MB/s | 15 MB 00:03
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 5.6 MB/s | 20 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Running scriptlet: mariadb-connector-c-3.0.6-8.p01.ky10.aarch64 1/1
Preparing : 1/1
Running scriptlet: apr-1.7.0-4.ky10.aarch64 1/15
Installing : apr-1.7.0-4.ky10.aarch64 1/15
Running scriptlet: apr-1.7.0-4.ky10.aarch64 1/15
Upgrading : libselinux-3.1-1.se.05.ky10.aarch64 2/15
Installing : mariadb-connector-c-3.0.6-8.p01.ky10.aarch64 3/15
Running scriptlet: apr-util-1.6.1-15.ky10.aarch64 4/15
Installing : apr-util-1.6.1-15.ky10.aarch64 4/15
Running scriptlet: apr-util-1.6.1-15.ky10.aarch64 4/15
Installing : httpd-tools-2.4.43-26.p01.ky10.aarch64 5/15
Running scriptlet: mailcap-2.1.49-3.ky10.noarch 6/15
Installing : mailcap-2.1.49-3.ky10.noarch 6/15
Running scriptlet: mailcap-2.1.49-3.ky10.noarch 6/15
Running scriptlet: httpd-filesystem-2.4.43-26.p01.ky10.noarch 7/15
Installing : httpd-filesystem-2.4.43-26.p01.ky10.noarch 7/15
Installing : kylin-logos-1.0-6.8.p01.ky10.noarch 8/15
Running scriptlet: kylin-logos-1.0-6.8.p01.ky10.noarch 8/15
Installing : httpd-help-2.4.43-26.p01.ky10.noarch 9/15
Installing : mod_http2-1.15.13-2.ky10.aarch64 10/15
Installing : httpd-2.4.43-26.p01.ky10.aarch64 11/15
Running scriptlet: httpd-2.4.43-26.p01.ky10.aarch64 11/15
Upgrading : python3-libselinux-3.1-1.se.05.ky10.aarch64 12/15
Cleanup : python3-libselinux-2.9-se.06.ky10.aarch64 13/15
Obsoleting : libselinux-utils-2.9-se.06.ky10.aarch64 14/15
warning: file /usr/share/man/man8/togglesebool.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/setenforce.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/selinuxexeccon.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/selinuxenabled.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/selinux.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/sefcontext_compile.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/matchpathcon.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/getsebool.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/getenforce.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/booleans.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man8/avcstat.8.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/x_contexts.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/virtual_image_context.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/virtual_domain_context.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/user_contexts.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/seusers.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/service_seusers.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/sepgsql_contexts.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/selabel_x.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/selabel_media.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/selabel_file.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/selabel_db.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/securetty_types.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/secolor.conf.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/removable_context.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/media.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/local.users.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/file_contexts.subs_dist.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/file_contexts.subs.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/file_contexts.local.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/file_contexts.homedirs.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/file_contexts.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/failsafe_context.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/default_type.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/default_contexts.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/customizable_types.5.gz: remove failed: No such file or directory
warning: file /usr/share/man/man5/booleans.5.gz: remove failed: No such file or directory
Cleanup : libselinux-2.9-se.06.ky10.aarch64 15/15
Running scriptlet: kylin-logos-1.0-6.8.p01.ky10.noarch 15/15
Running scriptlet: httpd-2.4.43-26.p01.ky10.aarch64 15/15
Running scriptlet: libselinux-2.9-se.06.ky10.aarch64 15/15
Verifying : kylin-logos-1.0-6.8.p01.ky10.noarch 1/15
Verifying : apr-1.7.0-4.ky10.aarch64 2/15
Verifying : apr-util-1.6.1-15.ky10.aarch64 3/15
Verifying : httpd-2.4.43-26.p01.ky10.aarch64 4/15
Verifying : httpd-filesystem-2.4.43-26.p01.ky10.noarch 5/15
Verifying : httpd-help-2.4.43-26.p01.ky10.noarch 6/15
Verifying : httpd-tools-2.4.43-26.p01.ky10.aarch64 7/15
Verifying : mailcap-2.1.49-3.ky10.noarch 8/15
Verifying : mariadb-connector-c-3.0.6-8.p01.ky10.aarch64 9/15
Verifying : mod_http2-1.15.13-2.ky10.aarch64 10/15
Verifying : libselinux-3.1-1.se.05.ky10.aarch64 11/15
Verifying : libselinux-2.9-se.06.ky10.aarch64 12/15
Verifying : libselinux-utils-2.9-se.06.ky10.aarch64 13/15
Verifying : python3-libselinux-3.1-1.se.05.ky10.aarch64 14/15
Verifying : python3-libselinux-2.9-se.06.ky10.aarch64 15/15
Upgraded:
libselinux-3.1-1.se.05.ky10.aarch64 python3-libselinux-3.1-1.se.05.ky10.aarch64
Installed:
httpd-2.4.43-26.p01.ky10.aarch64 kylin-logos-1.0-6.8.p01.ky10.noarch apr-1.7.0-4.ky10.aarch64 apr-util-1.6.1-15.ky10.aarch64
httpd-filesystem-2.4.43-26.p01.ky10.noarch httpd-help-2.4.43-26.p01.ky10.noarch httpd-tools-2.4.43-26.p01.ky10.aarch64 mailcap-2.1.49-3.ky10.noarch
mariadb-connector-c-3.0.6-8.p01.ky10.aarch64 mod_http2-1.15.13-2.ky10.aarch64
Complete!
3.4.3 将httpd服务设置开机自启
[root@395e9257b616 /]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
3.5 将启动的pod重新封装成iamges镜像
3.5.1 停止pod
[root@localhost ~]# docker stop 395e9257b616
395e9257b616
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
395e9257b616 df7a9105d15e "/sbin/init" 12 minutes ago Exited (137) 23 seconds ago kylin-test1
3.5.2 将pod封装成docker镜像
[root@localhost ~]# docker commit 395e9257b616 kylin-sp1-0518-http
sha256:e0a14457b8d40bf745386d527b64e91ead42876460b2a95d4d26dc240929421a
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kylin-sp1-0518-http latest e0a14457b8d4 27 seconds ago 549MB
kylin-server-10-sp1-0518-aarch b20 df7a9105d15e 3 years ago 411MB
3.6 使用封装好的镜像下发pod并映射端口(8001:80)
[root@localhost ~]# docker run --privileged=true -d -p 8001:80 --name kylin-test2 kylin-sp1-0518-http:latest /sbin/init
d75211e617b6166799d5b716447c405556393c31a60fd774a4c765f30aea8dc2
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
kylin-sp1-0518-http latest e0a14457b8d4 2 minutes ago 549MB
kylin-server-10-sp1-0518-aarch b20 df7a9105d15e 3 years ago 411MB
[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d75211e617b6 kylin-sp1-0518-http:latest "/sbin/init" 13 seconds ago Up 12 seconds 0.0.0.0:8001->80/tcp kylin-test2
395e9257b616 df7a9105d15e "/sbin/init" 15 minutes ago Exited (137) 4 minutes ago kylin-test1
四、使用curl命令验证
[root@localhost ~]# curl 192.168.122.185:8001
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Apache HTTP Server on Kylin Linux Advanced Server </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #fff;
color: #000;
font-size: 0.9em;
font-family: sans-serif,helvetica;
margin: 0;
padding: 0;
}
:link {
color: #c00;
}
:visited {
color: #c00;
}
a:hover {
color: #f50;
}
h1 {
text-align: center;
margin: 0;
padding: 0.6em 2em 0.4em;
background-color: #900;
color: #fff;
font-weight: normal;
font-size: 1.75em;
border-bottom: 2px solid #000;
}
h1 strong {
font-weight: bold;
}
h2 {
font-size: 1.1em;
font-weight: bold;
}
hr {
display: none;
}
.content {
padding: 1em 5em;
}
.content-columns {
/* Setting relative positioning allows for
absolute positioning for sub-classes */
position: relative;
padding-top: 1em;
}
.content-column-left {
/* Value for IE/Win; will be overwritten for other browsers */
width: 47%;
padding-right: 3%;
float: left;
padding-bottom: 2em;
}
.content-column-left hr {
display: none;
}
.content-column-right {
/* Values for IE/Win; will be overwritten for other browsers */
width: 47%;
padding-left: 3%;
float: left;
padding-bottom: 2em;
}
.content-columns>.content-column-left, .content-columns>.content-column-right {
/* Non-IE/Win */
}
img {
border: 2px solid #fff;
padding: 2px;
margin: 2px;
}
a:hover img {
border: 2px solid #f50;
}
/*]]>*/
</style>
</head>
<body>
<h1>Kylin Linux Advanced Server <strong>Test Page</strong></h1>
<div class="content">
<div class="content-middle">
<p>This page is used to test the proper operation of the Apache HTTP server after it has been installed. If you can read this page, it means that the Apache HTTP server installed at this site is working properly.</p>
</div>
<hr />
<div class="content-columns">
<div class="content-column-left">
<h2>If you are a member of the general public:</h2>
<p>The fact that you are seeing this page indicates that the website you just visited is either experiencing problems, or is undergoing routine maintenance.</p>
<p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p>
<p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p>
<p>For information on Kylin Linux Advanced Server , please visit the <a href="http://www.kylinos.cn/">Kylin, Inc. website</a>. The documentation for Kylin Linux is <a href="http://www.kylinos.cn/">available on the Kylin, Inc. website</a>.</p>
<hr />
</div>
<div class="content-column-right">
<h2>If you are the website administrator:</h2>
<p>You may now add content to the directory <tt>/var/www/html/</tt>. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>
<p>You are free to use the image below on web sites powered by the Apache HTTP Server:</p>
<p align="center"><a href="http://httpd.apache.org/"><img src="/icons/apache_pb2.gif" alt="[ Powered by Apache ]"/></a></p>
</div>
</div>
</div>
</body>
</html>