Build Docker Base Image for CentOS 7.x

… (with tweak for running without nested virtualization)

Environment Setup

Linux VM – CentOS 7.3 Minimal
– SELINUX Disabled
– Firewall Disabled

Step #1a: Install Docker

curl -sfo /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y epel-release docker-ce 
systemctl enable docker
systemctl start docker

Step #1b: Install build tools

yum install -y lorax anaconda-tui

Build the Image

Step #2: Generate the tarball

mkdir -p docker-dev-centos && cd docker-dev-centos

curl -sO http://centos.mirror.constant.com/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1611.iso

curl -sO https://raw.githubusercontent.com/CentOS/sig-cloud-instance-build/master/docker/centos-7.ks

### prevent CentOS 7.3 from installing open-vm-tools-desktop
sed -i '/yum-plugin-ovl/a @platform-vmware --nodefaults' centos-7.ks

livemedia-creator --make-tar --no-virt \
--iso=CentOS-7-x86_64-NetInstall-1611.iso \
--ks=centos-7.ks \
--image-name=centos-root.tar.xz

When installing RHEL 7.3 as a vmware guest, the installer (Anaconda) automatically detects the virtualization host, then installs the VMware Tools (irrelevant for containers).
@TWEAK – ref: https://access.redhat.com/discussions/2770061

Step #3a: Import tarball (no tag)

cat /var/tmp/centos-root.tar.xz | docker import - mycentos

Step #3b: Import tarball (with tag=datestamp)

STAMP=$(date +%Y-%m-%d)
cat /var/tmp/centos-root.tar.xz | docker import - mycentos:$STAMP
docker tag mycentos:$STAMP mycentos

Test the Image

docker run -it --rm mycentos /bin/bash

[root@05eaed83571f /]# rpm -qa | wc -l
141

Query packages

docker run -it --rm mycentos rpm -qa --queryformat "%{NAME}\t%{VERSION}\t%{RELEASE}\t%{ARCH}\n"

Profit!