Docker容器学习梳理--手动制作系统镜像

时间:2022-04-23
本文章向大家介绍Docker容器学习梳理--手动制作系统镜像,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

docker官方和个人发布的镜像由于版本等各种原因,漏洞较多,已统计Docker Hub超过30%的官方镜像包含高危漏洞。此外,由于网络等原因也会造成docker pull下载镜像的速度很慢。基于这种情况,我们可以手动定制docker系统镜像。

以下记录了在centos7上做docker镜像的操作记录: 1)镜像制作脚本:mkimage-yum.sh

下载脚本地址:https://pan.baidu.com/s/1geTSQCN 提取密码:qsss

或者直接wget https://raw.githubusercontent.com/docker/docker/master/contrib/mkimage-yum.sh

2)执行脚本 [root@linux-node2 ~]# chmod 755 mkimage-yum.sh [root@linux-node2 ~]# ./mkimage-yum.sh -y /etc/yum.conf centos7

3)脚本执行成功后,检查docker本地镜像 [root@linux-node2 ~]# docker images

REPOSITORY                              TAG                 IMAGE ID            CREATED              SIZE
centos7                                 7.3.1611            1d7e06aab5db        About a minute ago   264.7 MB
centos                                  latest              67591570dd29        9 weeks ago          191.8 MB

如上已经发现了自己制定的镜像centos7

4)使用制定的镜像启动容器 [root@linux-node2 ~]# docker run -i -t centos7 /bin/bash Unable to find image 'centos7:latest' locally Pulling repository docker.io/library/centos7 docker: Error: image library/centos7:latest not found. See 'docker run --help'.

发现有报错是因为:上面制定的centos7镜像的TAG不是默认的latest,而启动时会默认带latest

所以启动时需要跟上镜像自己的TAG信息: [root@linux-node2 ~]# docker run -i -t centos7:7.3.1611 /bin/bash [root@2ba57568e836 /]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)