github.com/powellquiring/docker@v1.6.0-rc1/contrib/mkimage-yum.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Create a base CentOS Docker image. 4 # 5 # This script is useful on systems with yum installed (e.g., building 6 # a CentOS image on CentOS). See contrib/mkimage-rinse.sh for a way 7 # to build CentOS images on other systems. 8 9 usage() { 10 cat <<EOOPTS 11 $(basename $0) [OPTIONS] <name> 12 OPTIONS: 13 -y <yumconf> The path to the yum config to install packages from. The 14 default is /etc/yum.conf. 15 EOOPTS 16 exit 1 17 } 18 19 # option defaults 20 yum_config=/etc/yum.conf 21 while getopts ":y:h" opt; do 22 case $opt in 23 y) 24 yum_config=$OPTARG 25 ;; 26 h) 27 usage 28 ;; 29 \?) 30 echo "Invalid option: -$OPTARG" 31 usage 32 ;; 33 esac 34 done 35 shift $((OPTIND - 1)) 36 name=$1 37 38 if [[ -z $name ]]; then 39 usage 40 fi 41 42 #-------------------- 43 44 target=$(mktemp -d --tmpdir $(basename $0).XXXXXX) 45 46 set -x 47 48 mkdir -m 755 "$target"/dev 49 mknod -m 600 "$target"/dev/console c 5 1 50 mknod -m 600 "$target"/dev/initctl p 51 mknod -m 666 "$target"/dev/full c 1 7 52 mknod -m 666 "$target"/dev/null c 1 3 53 mknod -m 666 "$target"/dev/ptmx c 5 2 54 mknod -m 666 "$target"/dev/random c 1 8 55 mknod -m 666 "$target"/dev/tty c 5 0 56 mknod -m 666 "$target"/dev/tty0 c 4 0 57 mknod -m 666 "$target"/dev/urandom c 1 9 58 mknod -m 666 "$target"/dev/zero c 1 5 59 60 # amazon linux yum will fail without vars set 61 if [ -d /etc/yum/vars ]; then 62 mkdir -p -m 755 "$target"/etc/yum 63 cp -a /etc/yum/vars "$target"/etc/yum/ 64 fi 65 66 yum -c "$yum_config" --installroot="$target" --releasever=/ --setopt=tsflags=nodocs \ 67 --setopt=group_package_types=mandatory -y groupinstall Core 68 yum -c "$yum_config" --installroot="$target" -y clean all 69 70 cat > "$target"/etc/sysconfig/network <<EOF 71 NETWORKING=yes 72 HOSTNAME=localhost.localdomain 73 EOF 74 75 # effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb 76 # --keep-services "$target". Stolen from mkimage-rinse.sh 77 # locales 78 rm -rf "$target"/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} 79 # docs 80 rm -rf "$target"/usr/share/{man,doc,info,gnome/help} 81 # cracklib 82 rm -rf "$target"/usr/share/cracklib 83 # i18n 84 rm -rf "$target"/usr/share/i18n 85 # sln 86 rm -rf "$target"/sbin/sln 87 # ldconfig 88 rm -rf "$target"/etc/ld.so.cache 89 rm -rf "$target"/var/cache/ldconfig/* 90 91 version= 92 for file in "$target"/etc/{redhat,system}-release 93 do 94 if [ -r "$file" ]; then 95 version="$(sed 's/^[^0-9\]*\([0-9.]\+\).*$/\1/' "$file")" 96 break 97 fi 98 done 99 100 if [ -z "$version" ]; then 101 echo >&2 "warning: cannot autodetect OS version, using '$name' as tag" 102 version=$name 103 fi 104 105 tar --numeric-owner -c -C "$target" . | docker import - $name:$version 106 docker run -i -t $name:$version echo success 107 108 rm -rf "$target"