测试环境
Centos7 宿主机:5.4.100-1.el7.elrepo.x86_64 Docker:20.10.3
supermin安装
# 安装epel源 yum install supermin*
制作镜像
制作镜像需要使用root用户制作,其他用户制作的镜像可能会出现一些预料不到的问题
创建一个临时目录(这个不重要)
mkdir -pv /home/docker-test/centos7_base
cd /home/docker-test/centos7_base
步骤-1
supermin5 -v --prepare bash coreutils -o supermin.d
-v 激活调试消息,可以看见操作信息 --prepare 准备supermin需要的工具 base、coreutils 是需要的工具,如果用yum需要添加yum命令 -o 设置一个输出目录 supermin.d 输出的目录名称
输出如下内容:
[root@localhost centos7_base]# supermin5 -v --prepare bash coreutils -o supermin.d
supermin: version: 5.1.19
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: prepare: bash coreutils
supermin: packages specified on the command line:
- bash-4.2.46-34.el7.x86_64
- coreutils-8.22-24.el7_9.2.x86_64
supermin: writing supermin.d.tkd20i40/packages
supermin: after resolving dependencies there are 41 packages:
- basesystem-10.0-7.el7.centos.noarch
- bash-4.2.46-34.el7.x86_64
- ca-certificates-2020.2.41-70.0.el7_8.noarch
- centos-release-7-9.2009.1.el7.centos.x86_64
- chkconfig-1.7.6-1.el7.x86_64
- coreutils-8.22-24.el7_9.2.x86_64
- filesystem-3.2-25.el7.x86_64
- gawk-4.0.2-4.el7_3.1.x86_64
- glibc-2.17-323.el7_9.x86_64
- glibc-common-2.17-323.el7_9.x86_64
- gmp-1:6.0.0-15.el7.x86_64
- grep-2.20-3.el7.x86_64
- info-5.1-5.el7.x86_64
- keyutils-libs-1.5.8-3.el7.x86_64
- krb5-libs-1.15.1-50.el7.x86_64
- libacl-2.2.51-15.el7.x86_64
- libattr-2.4.46-13.el7.x86_64
- libcap-2.22-11.el7.x86_64
- libcom_err-1.42.9-19.el7.x86_64
- libffi-3.0.13-19.el7.x86_64
- libgcc-4.8.5-44.el7.x86_64
- libselinux-2.5-15.el7.x86_64
- libsepol-2.5-10.el7.x86_64
- libstdc++-4.8.5-44.el7.x86_64
- libtasn1-4.10-1.el7.x86_64
- libverto-0.2.5-4.el7.x86_64
- ncurses-5.9-14.20130511.el7_4.x86_64
- ncurses-base-5.9-14.20130511.el7_4.noarch
- ncurses-libs-5.9-14.20130511.el7_4.x86_64
- nspr-4.25.0-2.el7_9.x86_64
- nss-softokn-freebl-3.53.1-6.el7_9.x86_64
- nss-util-3.53.1-1.el7_9.x86_64
- openssl-libs-1:1.0.2k-21.el7_9.x86_64
- p11-kit-0.23.5-3.el7.x86_64
- p11-kit-trust-0.23.5-3.el7.x86_64
- pcre-8.32-17.el7.x86_64
- popt-1.13-16.el7.x86_64
- sed-4.2.2-7.el7.x86_64
- setup-2.8.71-11.el7.noarch
- tzdata-2021a-1.el7.noarch
- zlib-1.2.7-19.el7_9.x86_64
Loaded plugins: fastestmirror, product-id
Loading mirror speeds from cached hostfile
* elrepo: hkg.mirror.rackspace.com
* epel: mirrors.ustc.edu.cn
(1/11): centos-release-7-9.2009.1.el7.centos.x86_64.rpm | 27 kB 00:00:00
(2/11): ca-certificates-2020.2.41-70.0.el7_8.noarch.rpm | 382 kB 00:00:00
(3/11): bash-4.2.46-34.el7.x86_64.rpm | 1.0 MB 00:00:00
(4/11): coreutils-8.22-24.el7_9.2.x86_64.rpm | 3.3 MB 00:00:01
(5/11): glibc-2.17-324.el7_9.x86_64.rpm | 3.6 MB 00:00:01
(6/11): grep-2.20-3.el7.x86_64.rpm | 344 kB 00:00:00
(7/11): info-5.1-5.el7.x86_64.rpm | 233 kB 00:00:00
(8/11): setup-2.8.71-11.el7.noarch.rpm | 166 kB 00:00:00
(9/11): krb5-libs-1.15.1-50.el7.x86_64.rpm | 809 kB 00:00:00
(10/11): openssl-libs-1.0.2k-21.el7_9.x86_64.rpm | 1.2 MB 00:00:00
(11/11): glibc-common-2.17-324.el7_9.x86_64.rpm | 12 MB 00:00:02
supermin: there are 61 config files
supermin: writing supermin.d.tkd20i40/base.tar.gz
./etc/issue
./etc/issue.net
./etc/os-release
./etc/system-release-cpe
./etc/yum.repos.d/CentOS-Base.repo
./etc/yum.repos.d/CentOS-CR.repo
./etc/yum.repos.d/CentOS-Debuginfo.repo
./etc/yum.repos.d/CentOS-Media.repo
./etc/yum.repos.d/CentOS-Sources.repo
./etc/yum.repos.d/CentOS-Vault.repo
./etc/yum.repos.d/CentOS-fasttrack.repo
./etc/yum.repos.d/CentOS-x86_64-kernel.repo
./etc/yum/vars/contentdir
./etc/yum/vars/infra
./etc/aliases
./etc/bashrc
./etc/csh.cshrc
./etc/csh.login
./etc/environment
./etc/exports
./etc/filesystems
./etc/group
./etc/gshadow
./etc/host.conf
./etc/hosts
./etc/hosts.allow
./etc/hosts.deny
./etc/inputrc
./etc/motd
./etc/passwd
./etc/printcap
./etc/profile
./etc/profile.d/csh.local
./etc/profile.d/sh.local
./etc/protocols
./etc/securetty
./etc/services
./etc/shadow
./etc/shells
./etc/subgid
./etc/subuid
./etc/krb5.conf
./etc/pki/ca-trust/ca-legacy.conf
./etc/default/nss
./etc/pki/tls/openssl.cnf
./etc/GREP_COLORS
./etc/profile.d/colorgrep.csh
./etc/profile.d/colorgrep.sh
./usr/share/info/dir
./etc/ld.so.conf
./etc/nsswitch.conf
./etc/rpc
./usr/lib64/gconv/gconv-modules
./etc/DIR_COLORS
./etc/DIR_COLORS.256color
./etc/DIR_COLORS.lightbgcolor
./etc/profile.d/colorls.csh
./etc/profile.d/colorls.sh
./etc/skel/.bash_logout
./etc/skel/.bash_profile
./etc/skel/.bashrc
supermin: renaming supermin.d.tkd20i40 to supermin.d
制作镜像时想包含某个命令
制作镜像时想包含某个命令,但又不知道在哪个包时,可以用yum whatprovides 来查找。
[root@localhost centos7_base]# yum whatprovides */ifconfig
Loaded plugins: fastestmirror, product-id, search-disabled-repos
Loading mirror speeds from cached hostfile
* elrepo: hkg.mirror.rackspace.com
* epel: mirrors.ustc.edu.cn
base/7/x86_64/filelists_db | 7.2 MB 00:00:00
docker-ce-stable/7/x86_64/filelists_db | 27 kB 00:00:00
elrepo/filelists_db | 34 kB 00:00:00
epel/x86_64/filelists_db | 12 MB 00:00:01
extras/7/x86_64/filelists_db | 235 kB 00:00:00
updates/7/x86_64/filelists_db | 5.5 MB 00:00:00
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : base
Matched from:
Filename : /sbin/ifconfig
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo : @base
Matched from:
Filename : /sbin/ifconfig
步骤-2
supermin5 -v --build --format chroot supermin.d -o appliance.d
--build 构建完全需要的工具 --format chroot设置输出格式
输入如下内容:
[root@localhost centos7_base]# supermin5 -v --build --format chroot supermin.d -o appliance.d
supermin: version: 5.1.19
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: build: supermin.d
supermin: reading the supermin appliance
supermin: build: visiting supermin.d/base.tar.gz type gzip base image (tar)
supermin: build: visiting supermin.d/packages type uncompressed packages
supermin: mapping package names to installed packages
supermin: resolving full list of package dependencies
supermin: build: 41 packages, including dependencies
supermin: build: 18633 files
supermin: build: 18633 files, after matching excludefiles
supermin: build: 18633 files, after adding hostfiles
supermin: build: 5464 files, after removing unreadable files
supermin: build: 5493 files, after munging
supermin: renaming appliance.d.dz5admv1 to appliance.d
步骤-3
封装docker镜像文件到归档文件中
echo 7 > appliance.d/etc/yum/vars/releasever
cp ~/.bashrc appliance.d/root/
tar --numeric-owner -cpf centos7_base.tar -C appliance.d .
步骤-4
导入tar归档文件到docker镜像列表中,以方便操作
cat centos7_base.tar | docker import - centos7-base:v1
运行镜像测试
docker run -it centos7-base:v1 /bin/bash