1. 准备
1)光驱挂载ISO镜像
export MOUNT_DIR=/mnt mount /dev/sr0 ${MOUNT_DIR}
2. 创建RHEL7基础镜像
1)创建rmp根目录
mkdir -p /ups/data/rhel76
export rpm_root=/ups/data/rhel76
2)初始化
rpm --root ${rpm_root} --initdb
3)安装rmp包(redhat-release-server rpm)
rpm --root ${rpm_root} -ivh ${MOUNT_DIR}/Packages/redhat-release-server-7.6-4.el7.x86_64.rpm
4)配置yum源
mkdir -p ${rpm_root}/etc/yum.repos.d/cat >${rpm_root}/etc/yum.repos.d/rhel7.repo<<EOF [rhel7] name=rhel7 baseurl=file://${MOUNT_DIR} enabled=1 EOF
5)加载GPG Key
rpm --root ${rpm_root} --import ${MOUNT_DIR}/RPM-GPG-KEY-redhat-*
6)最小化安装rhel7到${rpm_root}目录
yum -y groupinstall "core" --setopt=group_package_types=mandatory --installroot=${rpm_root}
备注:(group_package_types)
mandatory package groups/packages are always installed.
default package groups/packages are normally installed except if specified otherwise.
optional package groups/packages are only installed on demand.
7)创建镜像
tar -C ${rpm_root}/ -c . | docker import - biaobes/rhel:7.6
8)运行测试
docker run --hostname='rhel7-container' biaobes/rhel7:7.6 uname -a
9)发布镜像到公有仓库
docker push biaobes/rhel7:7.6