static ELF dependencies search for docker images

In my previous post ( http://glaudiston.blogspot.com.br/2015/06/how-to-make-very-very-small-docker.html ), 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:

#!/bin/bash
# use:
# getbash.sh /path/to/lib-or-elf.so

LIBLD=/lib64/ld-linux-x86-64.so.2;
LIB="$1";
function getdeps()
{
    {
        echo "$1";
        $LIBLD --list $1 |
                cut -d' ' -f3 | sort | uniq | 
                while read f;  
                do [ ! "$f" == "" ] && [ "$(echo -e "$deps" | grep -c "$f")" == "0" ] && {
                        deps="$deps\n$f";
                        getdeps "$f";
                };  
                done;
    } | 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 && 
 ./getdeps.sh "/path/to/your/elf" | 
 xargs -i cp -v "{}" ./deplibs;
Another simple script can copy all dependencies to a deps dir in current directory structure.
./getdeps.sh "/path/to/your/elf" | 
    while read f; 
    do d="./deps/$(dirname "$f")"; 
        [ ! -e "$d" ] && mkdir -pv "$d"; 
        cp -v "$f" "$d"; 
    done;
Don't forget to set the LD_LIBRARY_PATH or the /etc/ld.so.conf, 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
ENV LD_LIBRARY_PATH /deplibs

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

Comentários

Postagens mais visitadas