Skip to content
Advertisement

UnsatisfiedLinkError using openjdk:17 inside Docker container

I want to Dockerize a web application, which works perfectly fine locally. When trying to run the application inside Docker, an UnsatisfiedLinkError is thrown when invoking a function from the Nauty library.

To work with this library locally, the Spring application has to be started by doing

java -Djava.library.path="<PATH>/backend/lib/" -jar backend.jar

This library path points to the directory where the Nauty library (libnauty.so) resides. In my ~/.bashrc, I also had to set the environment variable LD_LIBRARY_PATH=<PATH>/backend/lib/:/usr/local/lib. After making these two changes, the application works fine and functions from the Nauty library can be invoked without any problems.

After Dockerizing the application, I get the following error when invoking a library function

java.lang.UnsatisfiedLinkError: no nauty in java.library.path: "/home/backend/lib/"

However, the libnauty.so file is copied to the Docker container and is present in /home/backend/lib directory. I also set the environment variable LD_LIBRARY_PATH in the Docker container. The issue however still remains.

I use docker-compose to set up the application. The Dockerfile for the back-end looks like this.

FROM openjdk:17-oracle
ARG JAR_FILE=target/*.jar
EXPOSE 8080
ENV LD_LIBRARY_PATH=/home/backend/lib/:/usr/local/lib
COPY ${JAR_FILE} /home/backend/backend.jar
COPY . /home/backend
ENTRYPOINT ["java", "-Djava.library.path="/home/backend/lib/"", "-jar", "/home/backend/backend.jar"]

Any pointers to how this issue could be solved would be greatly appreciated. I have looked around for quite some time now, but I can’t seem to fix the problem.

Advertisement

Answer

After hours of googling and debugging, the problem was the double quotes around the library path in the ENTRYPOINT. The correct way to specify it is just

ENTRYPOINT ["java", "-Djava.library.path=/home/backend/lib/", "-jar", "/home/backend/backend.jar"]
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement