#!/bin/bash
binfile=$1
currdir=$(cd $(dirname $0)/; pwd)
dstdir=$currdir/root/
if [ -z "$binfile" -o ! -e "$binfile" ]; then
echo "need arguments"
else
libs=$(ldd $binfile | grep '/lib' | sed -e "s,^\s*[^/]\+[^/]*[/],/,g" -e "s,(.*),,g")
echo "$libs" | while read line; do
echo "... $line"
libdir=$(dirname $line)
mkdir -vp $dstdir/$libdir
cp -vf $line $dstdir/$libdir/.
done
tmpdir=$(dirname $binfile)
mkdir -vp $dstdir/$tmpdir
cp -vf $binfile $dstdir/$tmpdir/.
fi
FROM scratch
COPY ./root /
ENV PATH="/bin"
./copybin.sh /bin/ls
./copybin.sh /bin/bash
docker build -t myimage .
docker run -it myimage bash