http://www.oschina.net/news/62897/docker-hub-contains-high-risk-vulnerabilities 这里有个统计,docker官方和个人发布的镜像由于版本等各种原因,漏洞较多,那我们如何自己从头开始做个定制的镜像呢?
对,找官方文档 http://docs.docker.com/articles/baseimages/,这里说明的很清楚了
试验如下:在centos7机器上做centos镜像
直接参考这个脚本
https://raw.githubusercontent.com/docker/docker/master/contrib/mkimage-yum.sh
./mkimage-yum.sh -y /etc/yum.conf centos7
执行如上脚本,成功后,就可以看到镜像了【docker images】,概要说明一下,主要是如下几步:
1.tmp目录下建立临时目录和文件系统
2.使用yum安装相关的软件包
3.软件包安装和信息定制
4.tar打包
5.清理
target=(mktemp−d−−tmpdir(mktemp−d−−tmpdir(basename $0).XXXXXX)
set -x
mkdir -m 755 "$target"/dev
mknod -m 600 "$target"/dev/console c 5 1
mknod -m 600 "$target"/dev/initctl p
mknod -m 666 "$target"/dev/full c 1 7
mknod -m 666 "$target"/dev/null c 1 3
mknod -m 666 "$target"/dev/ptmx c 5 2
mknod -m 666 "$target"/dev/random c 1 8
mknod -m 666 "$target"/dev/tty c 5 0
mknod -m 666 "$target"/dev/tty0 c 4 0
mknod -m 666 "$target"/dev/urandom c 1 9
mknod -m 666 "$target"/dev/zero c 1 5
# amazon linux yum will fail without vars set
if [ -d /etc/yum/vars ]; then
mkdir -p -m 755 "$target"/etc/yum
cp -a /etc/yum/vars "$target"/etc/yum/
fi
yum -c "yumconfig"−−installroot="yumconfig"−−installroot="target" --releasever=/ --setopt=tsflags=nodocs \
--setopt=group_package_types=mandatory -y groupinstall Core
yum -c "yumconfig"−−installroot="yumconfig"−−installroot="target" -y clean all
...
tar --numeric-owner -c -C "target".|dockerimport−target".|dockerimport−name:$version
docker run -i -t name:name:version echo success
rm -rf "$target"
(adsbygoogle = window.adsbygoogle || []).push({});