docker这个方便的工具可以快速的部署自己的应用,但是其中最基本的方式就是创建一个docker image,但是docker hub上并没有我们所需要的image,因此在某些情况下,可以自己创建一个minimal docker images;
介绍一个基于REDHAT系列的制基于该平台的docker images,适用于其他cpu哦,比如mips,sw等;
# Create a folder for our new root structure
# 创建根文件系统目录
$ export centos_root='/centos_image/rootfs'
$ mkdir -p ${centos_root}
# download and install the centos-release package, it contains our repository sources
# 下载centos-release,这里面包含了一个最小minimal rootfs最小的包
$ yum reinstall --downloadonly --downloaddir . centos-release
$ rpm --root ${centos_root} -ivh --nodepscentos-release*.rpm
# 安装包
$ yum -y --installroot=${centos_root} --setopt=tsflags='nodocs' --setopt=override_install_langs=en_US.utf8 install yum
# 将宿主机上的配置cp 到自己创建的根文件目录
# cp dns config file
$ cp /etc/resolv.conf {centos_root}/etc
# 为了保持仓库源一直可用,所以需要cp宿主机的源配置
$ cp /etc/yum.repos.d/* ${centos_root}/etc/yum.repos.d
# mount the device tree, as its required by some programms
# 创建根文件目录里面所需要的系统安装包,不过不同平台的image 存在不同的差异,有些最小的安装包,差tar
$ mount -o bind /dev {centos_root}/dev
$ chroot {centos_root}/bin/bash <
yum install -y procps-ng iputils
yum clean all
EOF
$ umount ${centos_root}/dev
# over
# 创建完毕
# 导入docker中,由于是rootfs文件系统,所以需要使用import 参数
$ tar -C ${centos_root} -c . |docker import - centos
网友评论