Last active
August 29, 2015 14:07
-
-
Save lostsnow/c5d5b5b1be66f88a1c67 to your computer and use it in GitHub Desktop.
build centos6 base image for docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
## requires running as root because filesystem package won't install otherwise, | |
## giving a cryptic error about /proc, cpio, and utime. As a result, /tmp | |
## doesn't exist. | |
[ $( id -u ) -eq 0 ] || { echo "must be root"; exit 1; } | |
tmpdir=$( mktemp -d ) | |
trap "echo removing ${tmpdir}; rm -rf ${tmpdir}" EXIT | |
febootstrap \ | |
-u http://mirrors.sohu.com/centos/6/updates/x86_64/ \ | |
-i bash \ | |
-i centos-release \ | |
-i yum \ | |
-i iputils \ | |
-i tar \ | |
-i which \ | |
-i wget \ | |
-i vim-minimal \ | |
-i http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm \ | |
centos6-min \ | |
${tmpdir} \ | |
http://mirrors.sohu.com/centos/6/os/x86_64/ | |
echo "Minimal image size" | |
febootstrap-minimize --keep-locale --keep-zoneinfo --keep-rpmdb --keep-services --keep-ldconfig "$tmpdir" | |
febootstrap-run ${tmpdir} -- sh -c 'echo "NETWORKING=yes" > /etc/sysconfig/network' | |
febootstrap-run ${tmpdir} -- sh -c 'echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network' | |
## remove unused locales | |
## https://github.com/jayjanssen/packer-percona/blob/master/provisioners/remove-extra-locales.sh | |
echo "remove unused locales" | |
febootstrap-run ${tmpdir} -- bash -c 'find /usr/share/locale -maxdepth 1 -mindepth 1 -type d | grep -v -e "en_US" | xargs rm -rf' | |
febootstrap-run ${tmpdir} -- bash -c 'localedef --list-archive | grep -v -e "en_US" | xargs localedef --delete-from-archive' | |
febootstrap-run ${tmpdir} -- mv /usr/lib/locale/locale-archive /usr/lib/locale/locale-archive.tmpl | |
febootstrap-run ${tmpdir} -- build-locale-archive | |
echo "remove ldconfig cache" | |
febootstrap-run ${tmpdir} -- bash -c 'rm -rf /etc/ld.so.cache' | |
febootstrap-run ${tmpdir} -- bash -c 'rm -rf /var/cache/ldconfig/*' | |
## set timezone of container to UTC | |
echo "set timezone" | |
#febootstrap-run ${tmpdir} -- ln -f /usr/share/zoneinfo/Etc/UTC /etc/localtime | |
febootstrap-run ${tmpdir} -- ln -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime | |
## xz gives the smallest size by far, compared to bzip2 and gzip, by like 50%! | |
echo "compress image" | |
febootstrap-run ${tmpdir} -- tar -cf - . | xz > centos6-min.tar.xz | |
echo "build image" | |
tag=${1:-latest} | |
cat centos6-min.tar.xz | docker import - centos6-base-min:${tag} | |
rm centos6-min.tar.xz | |
echo "done" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment