github.com/powellquiring/docker@v1.6.0-rc1/contrib/mkimage-rinse.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Create a base CentOS Docker image. 4 5 # This script is useful on systems with rinse available (e.g., 6 # building a CentOS image on Debian). See contrib/mkimage-yum.sh for 7 # a way to build CentOS images on systems with yum installed. 8 9 set -e 10 11 echo >&2 12 echo >&2 'warning: this script is deprecated - see mkimage.sh and mkimage/rinse' 13 echo >&2 14 15 repo="$1" 16 distro="$2" 17 mirror="$3" 18 19 if [ ! "$repo" ] || [ ! "$distro" ]; then 20 self="$(basename $0)" 21 echo >&2 "usage: $self repo distro [mirror]" 22 echo >&2 23 echo >&2 " ie: $self username/centos centos-5" 24 echo >&2 " $self username/centos centos-6" 25 echo >&2 26 echo >&2 " ie: $self username/slc slc-5" 27 echo >&2 " $self username/slc slc-6" 28 echo >&2 29 echo >&2 " ie: $self username/centos centos-5 http://vault.centos.org/5.8/os/x86_64/CentOS/" 30 echo >&2 " $self username/centos centos-6 http://vault.centos.org/6.3/os/x86_64/Packages/" 31 echo >&2 32 echo >&2 'See /etc/rinse for supported values of "distro" and for examples of' 33 echo >&2 ' expected values of "mirror".' 34 echo >&2 35 echo >&2 'This script is tested to work with the original upstream version of rinse,' 36 echo >&2 ' found at http://www.steve.org.uk/Software/rinse/ and also in Debian at' 37 echo >&2 ' http://packages.debian.org/wheezy/rinse -- as always, YMMV.' 38 echo >&2 39 exit 1 40 fi 41 42 target="${TMPDIR:-/var/tmp}/docker-rootfs-rinse-$distro-$$-$RANDOM" 43 44 cd "$(dirname "$(readlink -f "$BASH_SOURCE")")" 45 returnTo="$(pwd -P)" 46 47 rinseArgs=( --arch amd64 --distribution "$distro" --directory "$target" ) 48 if [ "$mirror" ]; then 49 rinseArgs+=( --mirror "$mirror" ) 50 fi 51 52 set -x 53 54 mkdir -p "$target" 55 56 sudo rinse "${rinseArgs[@]}" 57 58 cd "$target" 59 60 # rinse fails a little at setting up /dev, so we'll just wipe it out and create our own 61 sudo rm -rf dev 62 sudo mkdir -m 755 dev 63 ( 64 cd dev 65 sudo ln -sf /proc/self/fd ./ 66 sudo mkdir -m 755 pts 67 sudo mkdir -m 1777 shm 68 sudo mknod -m 600 console c 5 1 69 sudo mknod -m 600 initctl p 70 sudo mknod -m 666 full c 1 7 71 sudo mknod -m 666 null c 1 3 72 sudo mknod -m 666 ptmx c 5 2 73 sudo mknod -m 666 random c 1 8 74 sudo mknod -m 666 tty c 5 0 75 sudo mknod -m 666 tty0 c 4 0 76 sudo mknod -m 666 urandom c 1 9 77 sudo mknod -m 666 zero c 1 5 78 ) 79 80 # effectively: febootstrap-minimize --keep-zoneinfo --keep-rpmdb --keep-services "$target" 81 # locales 82 sudo rm -rf usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} 83 # docs 84 sudo rm -rf usr/share/{man,doc,info,gnome/help} 85 # cracklib 86 sudo rm -rf usr/share/cracklib 87 # i18n 88 sudo rm -rf usr/share/i18n 89 # yum cache 90 sudo rm -rf var/cache/yum 91 sudo mkdir -p --mode=0755 var/cache/yum 92 # sln 93 sudo rm -rf sbin/sln 94 # ldconfig 95 #sudo rm -rf sbin/ldconfig 96 sudo rm -rf etc/ld.so.cache var/cache/ldconfig 97 sudo mkdir -p --mode=0755 var/cache/ldconfig 98 99 # allow networking init scripts inside the container to work without extra steps 100 echo 'NETWORKING=yes' | sudo tee etc/sysconfig/network > /dev/null 101 102 # to restore locales later: 103 # yum reinstall glibc-common 104 105 version= 106 if [ -r etc/redhat-release ]; then 107 version="$(sed -E 's/^[^0-9.]*([0-9.]+).*$/\1/' etc/redhat-release)" 108 elif [ -r etc/SuSE-release ]; then 109 version="$(awk '/^VERSION/ { print $3 }' etc/SuSE-release)" 110 fi 111 112 if [ -z "$version" ]; then 113 echo >&2 "warning: cannot autodetect OS version, using $distro as tag" 114 sleep 20 115 version="$distro" 116 fi 117 118 sudo tar --numeric-owner -c . | docker import - $repo:$version 119 120 docker run -i -t $repo:$version echo success 121 122 cd "$returnTo" 123 sudo rm -rf "$target"