dockermavenfabric8djl

Create DockerFile using fabric8 that copies shared libraries


I am trying to run DJL(Deep java library) within an application on my Kubernetes Cluster( Debian 11 nodes).

I am using fabric8 and maven to dynamically create my DockerFile this is what generated so far:

FROM amazoncorretto:11-alpine-jdk
EXPOSE 8081
COPY maven /maven/
VOLUME ["/tmp"]
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/maven/showthem-web-api-0.0.1-SNAPSHOT.jar"]

but I think I need to copy the dependency the libstdc++ file from /usr/lib/x86_64-linux-gnu/libstdc++so.6 on the host to /maven

I also read that the best practice is to actually include this libstdc++ .so file in my docker image during build and not even copy files from the host into /maven... So not sure if my approach is the correct one. However, I would like to get this working using fabric8.

I attempted to add the LD_LIBRARY_PATH but it does not pick up the .so libraries.

FROM amazoncorretto:11-alpine-jdk
EXPOSE 8081
COPY maven /maven/
VOLUME ["/tmp"]
ENV LD_LIBRARY_PATH=/maven:$LD_LIBRARY_PATH
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/maven/showthem-web-api-0.0.1-SNAPSHOT.jar"

**updated I tried:

FROM amazoncorretto:11-alpine-jdk
EXPOSE 8081
COPY maven /maven/
RUN apt add libstdc++6
VOLUME ["/tmp"]
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/maven/showthem-web-api-0.0.1-SNAPSHOT.jar"]

This is example of my pom.xml file.

... amazoncorretto:11-alpine-jdk
apk add libstdc++6 ...

it is installing, but still get:

 Suppressed: java.lang.UnsatisfiedLinkError: Error loading shared library libstdc++.so.6: No such file or directory (needed by /root/.djl.ai/mxnet/1.9.0-mkl-linux-x86_64/libmxnet.so)
                at com.sun.jna.Native.open(Native Method) ~[jna-5.10.0.jar!/:5.10.0 (b0)]
                at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:191) ~[jna-5.10.0.jar!/:5.10.0 (b0)]
                ... 66 common frames omitted
        Suppressed: java.lang.UnsatisfiedLinkError: Error loading shared library libstdc++.so.6: No such file or directory (needed by /root/.djl.ai/mxnet/1.9.0-mkl-linux-x86_64/libmxnet.so)
                at com.sun.jna.Native.open(Native Method) ~[jna-5.10.0.jar!/:5.10.0 (b0)]
                at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:204) ~[jna-5.10.0.jar!/:5.10.0 (b0)]
                ... 66 common frames omitted

reference: https://github.com/deepjavalibrary/djl/issues/1748


Solution

  • my container now sees the .so depedencies. I am not sure why I had to add an extra layer, because my host system is Debian...but it works.

     <from>debian:11</from>                                             
        <runCmds>
           <run>apt-get update</run> 
            <run>apt-get -y install openjdk-11-jdk-headless</run> 
         </runCmds>
    

    when results in:

    FROM debian:11
    EXPOSE 8081
    COPY maven /maven/
    RUN apt-get update
    RUN apt-get -y install openjdk-11-jdk-headless