static ELF dependencies search for docker images

In my previous post ( ), I did a docker image from scratch for running bash. But bash itself don't solve many problems. We need to add our tools and dependencies.

I really don't know a tool to do it, so I wrote a bash script to solve that:

# use:
# /path/to/

function getdeps()
        echo "$1";
        $LIBLD --list $1 |
                cut -d' ' -f3 | sort | uniq | 
                while read f;  
                do [ ! "$f" == "" ] && [ "$(echo -e "$deps" | grep -c "$f")" == "0" ] && {
                        getdeps "$f";
    } | sort | uniq;

getdeps "${LIB}"

It just use the ld lib to list dependencies and extract the current path to it. Of course it don't can get another resources used by those libs but already is itself a lot of help on tracking it's dependencies.

So, in simples cases, it's halfway to get you static elf in docker running. You can choice if you want to copy all path or just all libs. I think it's better to copy all to one place like:

mkdir deplibs && 
 ./ "/path/to/your/elf" | 
 xargs -i cp -v "{}" ./deplibs;
Another simple script can copy all dependencies to a deps dir in current directory structure.
./ "/path/to/your/elf" | 
    while read f; 
    do d="./deps/$(dirname "$f")"; 
        [ ! -e "$d" ] && mkdir -pv "$d"; 
        cp -v "$f" "$d"; 
Don't forget to set the LD_LIBRARY_PATH or the /etc/, according your choice. If you put all your deps in a dir named deplibs, just add these 2 lines to your Dockerfile:
COPY deps/libs /deplibs

At this time you probably already know how proceed with your Dockerfile.


Postagens mais visitadas