试验如下:在centos7机器上做centos镜像
直接参考这个脚本
./mkimage-yum.sh -y /etc/yum.conf centos7
执行如上脚本,成功后,就可以看到镜像了【docker images】,概要说明一下,主要是如下几步:
1.tmp目录下建立临时目录和文件系统
2.使用yum安装相关的软件包
3.软件包安装和信息定制
4.tar打包
5.清理
建立目录结构[rootfs]
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"