Reputation: 771
I am building a Java application that I will be hosting in a docker container. Part of this application is to use this library:
https://github.com/wooio/htmltopdf-java
It takes a URL and converts it to a PDF document. However, when running the .jar
file through docker I get the error that it's missing native dependencies:
java.lang.UnsatisfiedLinkError: Unable to load library '/tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so': Native library (tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so) not found in resource path
This is documented in the last section of the link above, that it needs these libraries to run correctly:
I have modified my Dockerfile
to try to install these dependencies at the docker build:
FROM openjdk:8-jdk-alpine
RUN sh -c 'apk update && apk add libssl1.0 libx11 libxext libxrender libstdc++ freetype fontconfig'
COPY server/target/server-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
I am new to docker, but I found this snippet of code in an issue of the github repo. But I still cannot get it to work.
Can you spot the issue here why I cannot run the program?
I am still getting the error java.lang.UnsatisfiedLinkError: Unable to load library '/tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so': Native library (tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so) not found in resource path
But when SSHing into the Docker container and looking into the tmp
-folder the io.woo.htmltopdf
-library is listed. The path tmp/io.woo.htmltopdf/wkhtmltox/0.12.5/libwkhtmltox.so
also exists in the docker container.
Could it be something with the path settings? That the Java application is not using the correct path somehow?
The app.jar
that is being run is located in the root folder, where the tmp
folder is also located - so it should find it?
Upvotes: 4
Views: 2762
Reputation: 11
I got the same issue, by the way I used htmltopdf
version 1.0.8
but it's working on mac os, but when I used images docker.io/fabric8/s2i-java:3.0-java8
it's not working and then I try to down version to 1.0.6
and it's working
change
compile group: 'io.woo', name: 'htmltopdf', version: '1.0.8'
to
compile group: 'io.woo', name: 'htmltopdf', version: '1.0.6'
Upvotes: 1
Reputation: 771
I managed to do a workaround to this problem by using the native wkhtmltopdf
library together with the wkhtmltopdf java wrapper.
Upvotes: 2
Reputation: 811
Alpine Linux is built on musl libc, not glibc. My guess is that your native library is not compatible with musl.
You can try the openjdk:8-slim
instead. This one is built on Debian, it is slightly bigger than the alpine-based image, but it will be able to run libraries built for glibc.
You need to use apt to install additional packages, and a bit of research is needed to find which packages provide the libraries you need.
Try starting your Dockerfile with the following lines instead :
FROM openjdk:8-slim
RUN apt-get update && apt-get install -y --no-install-recommends \
libc6 \
libx11-6 \
libxext6 \
libxrender1 \
libstdc++ \
libssl1.0 \
libfreetype6 \
fontconfig \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
This generates a 1.37 Gb image though, most of which is from the installation of libstdc++ and all of its dependencies. There might be an opportunity for optimization here (do you really need the full C++ Stdlib for your application to function properly ?). Without this package, the image size drops to 256 Mb.
Upvotes: 1
Reputation: 98
I have also had problem with the alpine images, if you don't mind about the size of the image, I would try to use openjdk:8
as your provided image instead.
Upvotes: 1