基于国产化龙蜥8.6基础容器镜像制作支持ssh、telnet、python3的扩展容器镜像

国产化服务器操作系统比较主流的就是欧位和龙蜥,容器化环境考虑到兼容性问题,可以选择与centos全兼容的龙蜥系列。本文记录了基于龙蜥8.6基础镜像加装ssh、telnet、python3的过程。

一、拉取镜像

1、查找龙蜥基础镜像,使用docker search anolisos,可以看到官方基础镜像为openanolis/anolisos:

# docker search anolisos
NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
openanolis/anolisos                     Anolis OS is an open source Linux distributi…   25                                      
kuiboolabs/anolisos-8.6-gcc-c17         龙蜥8.6下的适配C17规范的C语言GCC编译环境                       0                                       
hongweiqin/anolisos-oceanbase           A tentative deploy of oceanbase.                0                                       
efreport/anolisos8                      Anolisos8 OS.                                   0                                       
taodev/anolisos                                                                         0                                       
kuiboolabs/anolisos-8.6-gcc-c17-cmake   龙蜥8.6下的适配C17规范的C语言GCC编译环境,增…                    0                                       
573320328/anolisos                                                                      0                                       
geasscore/anolisos-riscv64                                                              0                                       
gotoeasy/anolisos                       在龙蜥7.9基础上预装Nginx、Java8以及中文环境…                   0                                       
xiaolunalibaba/anolisos                 the test docker image                           0                                       
lhrbest/anolisos                                                                        0                                       
ofuxas3/anolisos-vulnerable                                                             0                                       
keetyhuang/anolisos8-docker             for docker images                               0                                       
xuxiaoweicomcn/svn                      龙蜥 Anolisos Subversion(SVN) docker 镜像           0                                       
xuxiaoweicomcn/git                      龙蜥 Anolisos git docker 镜像                       0                                       
yrcs/an8-nydus-mariadb                  MariaDB Server image for Nydus based on Anol…   0  

2、考虑兼容性及手头上有的操作系统ISO文件,经测试,8.6版anolisos可用,拉取并保存镜像:

[root@localhost dockerfile]# docker pull openanolis/anolisos:8.6
8.6: Pulling from openanolis/anolisos
719018114380: Pull complete 
Digest: sha256:9395d241fc1a41a592773629994c3c0fa48886dd99c75431d7a885fb842753fa
Status: Downloaded newer image for openanolis/anolisos:8.6
[root@localhost dockerfile]# docker images |grep anolisos    
openanolis/anolisos     8.6                 6f8a2912d1d7        16 months ago       205MB
[root@localhost dockerfile]# docker save -o anolisos8.6.tar openanolis/anolisos:8.6
[root@localhost dockerfile]# ll anolisos8.6.tar        
-rw------- 1 root root 202M 12月 20 09:26 anolisos8.6.tar

二、导入并测试镜像 

3、在目标服务器上将启动容器脚本写入文本,导入保存的镜像文件,运行脚本启动容器:

# vi 0-mkdocker-anolisos.sh
# cat 0-mkdocker-anolisos.sh 
docker run -itd --restart=always --name anolisos --privileged  -v /data/dockerdata:/opt -v /etc/localtime:/etc/localtime:ro openanolis/anolisos:8.6 /usr/sbin/init
# docker load -i anolisos8.6.tar 
068524d0c0b6: Loading layer [==================================================>]  211.2MB/211.2MB
Loaded image: openanolis/anolisos:8.6
# sh 0-mkdocker-anolisos.sh 
77af622f6696d6a0cfc4d5a99109139e91b9238de6491c3b537562215c355b58

4、进入容器,查看容器内系统版本信息,并查看ssh、python、python3的安装情况

# docker exec -it anolisos /bin/bash
[root@77af622f6696 /]# cat /etc/os-release 
NAME="Anolis OS"
VERSION="8.6"
ID="anolis"
ID_LIKE="rhel fedora centos"
VERSION_ID="8.6"
PLATFORM_ID="platform:an8"
PRETTY_NAME="Anolis OS 8.6"
ANSI_COLOR="0;31"
HOME_URL="https://openanolis.cn/"

[root@77af622f6696 /]# ssh -V
bash: ssh: command not found
[root@77af622f6696 /]# python --version
bash: python: command not found
[root@77af622f6696 /]# python3 --version
bash: python3: command not found

可见基础镜像中ssh、python、python3均未安装

三、给容器加装软件

1、修改repo文件将yum指向内网服务器,并依次安装所需软件:

[root@77af622f6696 /]# cd /etc/yum.repos.d/ 
[root@77af622f6696 yum.repos.d]# rm * -rf
[root@77af622f6696 yum.repos.d]# vi http.repo
[root@77af622f6696 yum.repos.d]# cat http.repo 
[Appstream]
name=Appstream
baseurl=http://192.168.122.226/AnolisOS/AnolisOS8.6U1/AppStream/
enable=1
gpgcheck=0
[BaseOS]
name=BaseOS
baseurl=http://192.168.122.226/AnolisOS/AnolisOS8.6U1/BaseOS/
enable=1
gpgcheck=0
[root@77af622f6696 yum.repos.d]# dnf install openssh-clients
Failed to set locale, defaulting to C.UTF-8
Appstream                                                                                                                    17 MB/s | 5.1 MB     00:00    
BaseOS                                                                                                                       13 MB/s | 5.2 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Wed Dec 20 10:07:17 2023.
Dependencies resolved.
============================================================================================================================================================
 Package                                Architecture                  Version                                           Repository                     Size
============================================================================================================================================================
Installing:
 openssh-clients                        x86_64                        8.0p1-13.0.1.an8                                  BaseOS                        667 k
Installing dependencies:
 libedit                                x86_64                        3.1-23.20170329cvs.0.1.an8                        BaseOS                         98 k
 openssh                                x86_64                        8.0p1-13.0.1.an8                                  BaseOS                        521 k

Transaction Summary
============================================================================================================================================================
Install  3 Packages

Total download size: 1.3 M
Installed size: 4.5 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): openssh-clients-8.0p1-13.0.1.an8.x86_64.rpm                                                                          9.0 MB/s | 667 kB     00:00    
(2/3): openssh-8.0p1-13.0.1.an8.x86_64.rpm                                                                                  4.2 MB/s | 521 kB     00:00    
(3/3): libedit-3.1-23.20170329cvs.0.1.an8.x86_64.rpm                                                                        764 kB/s |  98 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                       9.6 MB/s | 1.3 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                    1/1 
  Running scriptlet: openssh-8.0p1-13.0.1.an8.x86_64                                                                                                    1/3 
  Installing       : openssh-8.0p1-13.0.1.an8.x86_64                                                                                                    1/3 
  Installing       : libedit-3.1-23.20170329cvs.0.1.an8.x86_64                                                                                          2/3 
  Installing       : openssh-clients-8.0p1-13.0.1.an8.x86_64                                                                                            3/3 
  Running scriptlet: openssh-clients-8.0p1-13.0.1.an8.x86_64                                                                                            3/3 
  Verifying        : libedit-3.1-23.20170329cvs.0.1.an8.x86_64                                                                                          1/3 
  Verifying        : openssh-8.0p1-13.0.1.an8.x86_64                                                                                                    2/3 
  Verifying        : openssh-clients-8.0p1-13.0.1.an8.x86_64                                                                                            3/3 

Installed:
  libedit-3.1-23.20170329cvs.0.1.an8.x86_64              openssh-8.0p1-13.0.1.an8.x86_64              openssh-clients-8.0p1-13.0.1.an8.x86_64             

Complete!
[root@77af622f6696 yum.repos.d]# ssh -V
OpenSSH_8.0p1, OpenSSL 1.1.1k  FIPS 25 Mar 2021
[root@77af622f6696 yum.repos.d]# dnf install telnet
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:23 ago on Wed Dec 20 10:07:17 2023.
Dependencies resolved.
============================================================================================================================================================
 Package                           Architecture                      Version                                        Repository                         Size
============================================================================================================================================================
Installing:
 telnet                            x86_64                            1:0.17-76.0.1.an8                              BaseOS                             68 k

Transaction Summary
============================================================================================================================================================
Install  1 Package

Total download size: 68 k
Installed size: 114 k
Is this ok [y/N]: y
Downloading Packages:
telnet-0.17-76.0.1.an8.x86_64.rpm                                                                                           2.6 MB/s |  68 kB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                       2.5 MB/s |  68 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                    1/1 
  Installing       : telnet-1:0.17-76.0.1.an8.x86_64                                                                                                    1/1 
  Running scriptlet: telnet-1:0.17-76.0.1.an8.x86_64                                                                                                    1/1 
  Verifying        : telnet-1:0.17-76.0.1.an8.x86_64                                                                                                    1/1 

Installed:
  telnet-1:0.17-76.0.1.an8.x86_64                                                                                                                           

Complete!
[root@77af622f6696 yum.repos.d]# dnf install python3
Failed to set locale, defaulting to C.UTF-8
Last metadata expiration check: 0:00:34 ago on Wed Dec 20 10:07:17 2023.
Dependencies resolved.
============================================================================================================================================================
 Package                               Architecture             Version                                                   Repository                   Size
============================================================================================================================================================
Installing:
 python36                              x86_64                   3.6.8-38.module+an8.5.0+10578+67483ed2                    Appstream                    18 k
Installing dependencies:
 platform-python-pip                   noarch                   9.0.3-22.an8                                              BaseOS                      1.6 M
 python3-pip                           noarch                   9.0.3-22.an8                                              BaseOS                       19 k
 python3-setuptools                    noarch                   39.2.0-6.an8                                              BaseOS                      162 k
Enabling module streams:
 python36                                                       3.6                                                                                        

Transaction Summary
============================================================================================================================================================
Install  4 Packages

Total download size: 1.8 M
Installed size: 7.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): python3-pip-9.0.3-22.an8.noarch.rpm                                                                                  1.2 MB/s |  19 kB     00:00    
(2/4): python36-3.6.8-38.module+an8.5.0+10578+67483ed2.x86_64.rpm                                                           528 kB/s |  18 kB     00:00    
(3/4): python3-setuptools-39.2.0-6.an8.noarch.rpm                                                                           5.8 MB/s | 162 kB     00:00    
(4/4): platform-python-pip-9.0.3-22.an8.noarch.rpm                                                                           22 MB/s | 1.6 MB     00:00    
------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        24 MB/s | 1.8 MB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                    1/1 
  Installing       : python3-setuptools-39.2.0-6.an8.noarch                                                                                             1/4 
  Installing       : platform-python-pip-9.0.3-22.an8.noarch                                                                                            2/4 
  Installing       : python3-pip-9.0.3-22.an8.noarch                                                                                                    3/4 
  Installing       : python36-3.6.8-38.module+an8.5.0+10578+67483ed2.x86_64                                                                             4/4 
  Running scriptlet: python36-3.6.8-38.module+an8.5.0+10578+67483ed2.x86_64                                                                             4/4 
  Verifying        : python36-3.6.8-38.module+an8.5.0+10578+67483ed2.x86_64                                                                             1/4 
  Verifying        : platform-python-pip-9.0.3-22.an8.noarch                                                                                            2/4 
  Verifying        : python3-pip-9.0.3-22.an8.noarch                                                                                                    3/4 
  Verifying        : python3-setuptools-39.2.0-6.an8.noarch                                                                                             4/4 

Installed:
  platform-python-pip-9.0.3-22.an8.noarch                         python3-pip-9.0.3-22.an8.noarch          python3-setuptools-39.2.0-6.an8.noarch         
  python36-3.6.8-38.module+an8.5.0+10578+67483ed2.x86_64         

Complete!

本例完成了openssh-clients、telnet、python3的安装,其中ssh客户端为OpenSSH_8.0p1,python为3.6.8。

2、测试通过pip3加装python的扩展包

[root@77af622f6696 ~]# pip3 install ptyprocess-0.7.0-py2.py3-none-any.whl  pexpect-4.9.0-py2.py3-none-any.whl                                      WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Processing ./ptyprocess-0.7.0-py2.py3-none-any.whl
Processing ./pexpect-4.9.0-py2.py3-none-any.whl
Installing collected packages: ptyprocess, pexpect
Successfully installed pexpect-4.9.0 ptyprocess-0.7.0

测试成功。

3、添加ll别名,因为习惯使用ll别名,因此在镜像中添加别名:

[root@77af622f6696 ~]# ll
bash: ll: command not found
[root@77af622f6696 ~]# vi ~/.bashrc
[root@77af622f6696 ~]# cat ~/.bashrc |grep ll
alias ll='ls -alF'
[root@77af622f6696 ~]# alias ll='ls -alF'
[root@77af622f6696 ~]# ll
total 24
dr-xr-x---. 1 root root  42 Dec 20 11:03 ./
drwxr-xr-x. 1 root root  62 Dec 20 10:01 ../
-rw-------. 1 root root 614 Dec 20 10:47 .bash_history
-rw-r--r--. 1 root root  18 Jan 27  2021 .bash_logout
-rw-r--r--. 1 root root 176 Jan 27  2021 .bash_profile
-rw-r--r--. 1 root root 195 Dec 20 11:03 .bashrc
-rw-r--r--. 1 root root 100 Jan 27  2021 .cshrc
-rw-r--r--. 1 root root 129 Jan 27  2021 .tcshrc
[root@77af622f6696 ~]# 

四、将容器打包成镜像并导出

# docker ps
CONTAINER ID        IMAGE                     COMMAND             CREATED             STATUS              PORTS               NAMES
77af622f6696        openanolis/anolisos:8.6   "/usr/sbin/init"    About an hour ago   Up About an hour                        anolisos
# docker commit -m "anolisos:8.6 with ssh telnet python3" -a "daijianbing"  77af622f6696  anolisos:8.6v2                    
sha256:05202b3da6d8a06f423a37ffed4b69457c9f344522f0c840703a3824f5379cb7
# docker images|grep anolis
anolisos                8.6v2               05202b3da6d8        17 seconds ago      254MB
openanolis/anolisos     8.6                 6f8a2912d1d7        16 months ago       205MB
# docker save -o anolisos-8.6v2.tar anolisos:8.6v2
# ll an*
-rw-r-----. 1 root root 202M 12月 20 09:52 anolisos8.6.tar
-rw-------. 1 root root 250M 12月 20 10:52 anolisos-8.6v2.tar

打包后的镜像即可进行分发了。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代先生.重庆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值