从头创建一个最小的CentOS Docker镜像

一、从头创建一个CentOS的基础框架

首先安装好CentOS7,并在上面安装Docker,然后执行:

# /usr/local/bin/supermin --prepare yum -o supermin.d
# /usr/local/bin/supermin --build --format chroot supermin.d -o appliance.d

# cd appliance.d
# mv usr/share/locale/en usr/share/locale/en_US tmp
# rm -rf usr/share/locale/*
# mv tmp/en tmp/en_US usr/share/locale/
# mv usr/share/i18n/locales/en_US tmp
# rm -rf usr/share/i18n/locales/*
# mv tmp/en_US usr/share/i18n/locales/
# echo 7 > etc/yum/vars/releasever
# cd ..

# tar --numeric-owner -cpf centos7-zero.tar -C appliance.d .
# cat centos7-zero.tar | docker import - local/centos7-zero

二、安装必要的组件,完成一个最小的CentOS7镜像

在主机上执行:

# docker run -i -t local/centos7-zero /bin/bash

在container中执行:

# yum update -y
# yum install -y audit-libs basesystem bash binutils bzip2-libs ca-certificates centos-release chkconfig coreutils cpio cracklib cracklib-dicts curl cyrus-sasl-lib dbus-libs device-mapper device-mapper-libs diffutils elfutils-libelf expat fakesystemd file file-libs filesystem findutils gawk gdbm glib2 glibc glibc-common gmp gnupg2 gpgme grep groff-base gzip hardlink info iproute iptables iptables-services iputils keyutils-libs kmod-libs kpartx krb5-libs less libacl libassuan libattr libblkid libcap libcap-ng libcom_err libcroco libcurl libdb libdb-utils libffi libgcc libgcrypt libgomp libgpg-error libidn libmnl libmount libnetfilter_conntrack libnfnetlink libpwquality libselinux libsemanage libsepol libssh2 libstdc++ libtasn1 libunistring libuser libutempter libuuid libverto libxml2 lua ncurses ncurses-base ncurses-libs nspr nss nss-softokn nss-softokn-freebl nss-sysinit nss-tools nss-util openldap openssl-libs p11-kit p11-kit-trust pam pcre pinentry pkgconfig popt procps-ng pth pygpgme pyliblzma python python-iniparse python-libs python-pycurl python-urlgrabber pyxattr readline rootfiles rpm rpm-build-libs rpm-libs rpm-python sed setup shadow-utils shared-mime-info sqlite systemd-libs tzdata ustr util-linux vim-minimal which xz xz-libs yum yum-metadata-parser yum-plugin-fastestmirror zlib
# yum update -y && yum clean all
# exit

在主机上执行:

# docker export <container_id> > centos7-minimal.tar