其他分享
首页 > 其他分享> > [docker] 构建镜像

[docker] 构建镜像

作者:互联网

#!/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

标签:bin,binfile,dstdir,构建,镜像,docker,dirname,line,tmpdir
来源: https://www.cnblogs.com/timlinux/p/14640242.html