github.com/eatbyte/docker@v1.6.0/contrib/mkimage-unittest.sh (about) 1 #!/usr/bin/env bash 2 # Generate a very minimal filesystem based on busybox-static, 3 # and load it into the local docker under the name "docker-ut". 4 5 missing_pkg() { 6 echo "Sorry, I could not locate $1" 7 echo "Try 'apt-get install ${2:-$1}'?" 8 exit 1 9 } 10 11 BUSYBOX=$(which busybox) 12 [ "$BUSYBOX" ] || missing_pkg busybox busybox-static 13 SOCAT=$(which socat) 14 [ "$SOCAT" ] || missing_pkg socat 15 16 shopt -s extglob 17 set -ex 18 ROOTFS=`mktemp -d ${TMPDIR:-/var/tmp}/rootfs-busybox.XXXXXXXXXX` 19 trap "rm -rf $ROOTFS" INT QUIT TERM 20 cd $ROOTFS 21 22 mkdir bin etc dev dev/pts lib proc sys tmp 23 touch etc/resolv.conf 24 cp /etc/nsswitch.conf etc/nsswitch.conf 25 echo root:x:0:0:root:/:/bin/sh > etc/passwd 26 echo daemon:x:1:1:daemon:/usr/sbin:/bin/sh >> etc/passwd 27 echo root:x:0: > etc/group 28 echo daemon:x:1: >> etc/group 29 ln -s lib lib64 30 ln -s bin sbin 31 cp $BUSYBOX $SOCAT bin 32 for X in $(busybox --list) 33 do 34 ln -s busybox bin/$X 35 done 36 rm bin/init 37 ln bin/busybox bin/init 38 cp -P /lib/x86_64-linux-gnu/lib{pthread*,c*(-*),dl*(-*),nsl*(-*),nss_*,util*(-*),wrap,z}.so* lib 39 cp /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 lib 40 cp -P /usr/lib/x86_64-linux-gnu/lib{crypto,ssl}.so* lib 41 for X in console null ptmx random stdin stdout stderr tty urandom zero 42 do 43 cp -a /dev/$X dev 44 done 45 46 chmod 0755 $ROOTFS # See #486 47 tar --numeric-owner -cf- . | docker import - docker-ut 48 docker run -i -u root docker-ut /bin/echo Success. 49 rm -rf $ROOTFS