Skip to content

Instantly share code, notes, and snippets.

@tatsushid
Created September 30, 2014 11:27
Show Gist options
  • Save tatsushid/22d169ea1e91e8941773 to your computer and use it in GitHub Desktop.
Save tatsushid/22d169ea1e91e8941773 to your computer and use it in GitHub Desktop.
Script for building CentOS 3 i386 docker image
#!/usr/bin/env bash
#
# Create a base CentOS 3 Docker image.
#
# This script is useful on systems with yum installed (e.g., building
# a CentOS 3 image on CentOS 3). It is taken from
# https://github.com/docker/docker/blob/master/contrib/mkimage-yum.sh
# and modified for CentOS 3
usage() {
cat <<EOOPTS
$(basename $0) [OPTIONS]
OPTIONS:
-y <yumconf> The path to the yum config to install packages from. The
default is /etc/yum.conf.
EOOPTS
exit 1
}
# option defaults
yum_config=/etc/yum.conf
while getopts ":y:h" opt; do
case $opt in
y)
yum_config=$OPTARG
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG"
usage
;;
esac
done
shift $((OPTIND - 1))
#--------------------
target=$(mktemp -d /tmp/$(basename $0).XXXXXX)
#target="/tmp/$(basename $0)"
mkdir -p "$target/var/lib/rpm"
#rpm --initdb --dbpath "$target/var/lib/rpm"
rpm --import --dbpath "$target/var/lib/rpm" http://vault.centos.org/3.9/os/i386/RPM-GPG-KEY
rpm --import --dbpath "$target/var/lib/rpm" http://vault.centos.org/3.9/os/i386/RPM-GPG-KEY-CentOS-3
set -x
mkdir -m 755 "$target"/dev
mknod -m 600 "$target"/dev/console c 5 1
mknod -m 600 "$target"/dev/initctl p
mknod -m 666 "$target"/dev/full c 1 7
mknod -m 666 "$target"/dev/null c 1 3
mknod -m 666 "$target"/dev/ptmx c 5 2
mknod -m 666 "$target"/dev/random c 1 8
mknod -m 666 "$target"/dev/tty c 5 0
mknod -m 666 "$target"/dev/tty0 c 4 0
mknod -m 666 "$target"/dev/urandom c 1 9
mknod -m 666 "$target"/dev/zero c 1 5
yum -c "$yum_config" --installroot="$target" -y groupinstall Core
yum -c "$yum_config" --installroot="$target" -y clean all
cp -f "$yum_config" "$target/etc/"
rpm --rebuilddb --dbpath "$target/var/lib/rpm"
cat > "$target"/etc/sysconfig/network <<EOF
NETWORKING=yes
HOSTNAME=localhost.localdomain
EOF
# effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb
# --keep-services "$target". Stolen from mkimage-rinse.sh
# locales
rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive}
# docs
rm -rf "$target"/usr/share/{man,doc,info,gnome/help}
# cracklib
rm -rf "$target"/usr/share/cracklib
# i18n
rm -rf "$target"/usr/share/i18n
# sln
rm -rf "$target"/sbin/sln
## ldconfig
#rm -rf "$target"/etc/ld.so.cache
#rm -rf "$target"/var/cache/ldconfig/*
version=
tar --numeric-owner -czf os_image.tar.gz -C "$target" .
rm -rf "$target"
@tatsushid
Copy link
Author

It generates os_image.tar.gz file for docker import command

@mcandre
Copy link

mcandre commented Jun 4, 2015

Does this work for building CentOS 3.3? When I try to install the Base group, yum complains that it can't find any groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment