0

I am installing a java application in a docker container. It runs fine but I keep gettig this error in the logs:

INFO 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [/usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib]

So, I am trying to install this APR package by following this and this, and installing tomcat native by adding this line in my dockerfile:

RUN apt-get install -y libtcnative-1

However, when add this line, I get the following message in the logs:

ERROR 1 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : An incompatible version [1.1.33] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

I tried installing:

apt-get install -y openjdk-8-jdk libapr1-dev

and

apt-get install -y openjdk-8-jdk libtcnative-1 libapr1-dev

But none of these worked .. I keep on getting the same messages.

I also tried installing from source by following the first answer here, but this did not also work.

Here is the rest of my dockerfile:

FROM ubuntu:16.04

RUN apt-get update \
 && apt-get install -y software-properties-common python-software-properties \
 && add-apt-repository ppa:mozillateam/ppa \
 && apt-get update \
 && apt-get install -y firefox firefox-esr

RUN apt-get install -y libtcnative-1 openjdk-8-jdk 

Any help is appreciated. Thanks!

deann
  • 756
  • 9
  • 24
  • *"I keep gettig this error"* but the log record is `INFO`, so it's not an *error*. It is an *informational* log message. – Andreas Jun 11 '19 at 16:22
  • From the message, I am left with the impression that I should be using this library for production, and I want to use this dockerfile in production as well – deann Jun 11 '19 at 16:24
  • When I am running this locally outside of docker, I am not getting this message. Also, I use gradlee to build the jar outside the container. I am wondering if this might have sth to do with it.. – deann Jun 11 '19 at 16:25
  • I'm sorry, but which part of that dockerfile installs Tomcat? – Andreas Jun 11 '19 at 16:26
  • Assuming you don't install Tomcat, but it is embedded in your code, then you obviously need an APR file that matches the version of Tomcat embedded in your code, so obtaining that should be part of your Gradle build, and the APR file should be delivered together with the jar file. – Andreas Jun 11 '19 at 16:30
  • @Andreas I think this line installs it - RUN apt-get install -y libtcnative-1. I will try adding the code and running gradlew build inside the container so that versions match. – deann Jun 11 '19 at 17:45
  • Why do you think installing `libtcnative-1` installs all of Tomcat? It just installs the optional library file *used* by Tomcat. – Andreas Jun 11 '19 at 17:52

1 Answers1

1

In case someone still is interested, here is what I did:

  1. Download the latest apr and tcnative from Apache and extract the archives into the directory where your Dockerfile is
  2. Perform a multistage build. The first stage builds the libraries:
    FROM adoptopenjdk/openjdk11:jdk-11.0.1.13 AS build
    ADD apr-1.7.0 $HOME/apr-1.7.0
    ADD tcnative $HOME/tcnative
    ARG DEBIAN_FRONTEND=noninteractive    
    RUN apt-get update -y && \
        apt-get -y upgrade && \
        apt-get install -y build-essential libssl-dev
    WORKDIR $HOME/apr-1.7.0
    RUN ./configure && make && make install

    WORKDIR $HOME/tcnative
    RUN ./configure --with-apr=/usr/local/apr/bin/apr-1-config  --with-java-home=$JAVA_HOME  --with-ssl=$HOME/OPENSSL --prefix=/usr/local/apr
    RUN make && make install
  1. The second stage builds the production server:
    FROM adoptopenjdk/openjdk11:jre-11.0.10_9
    ARG DEBIAN_FRONTEND=noninteractive
    RUN apt-get update -y && \
        apt-get -y upgrade && \
        apt-get install -y --no-install-recommends libssl-dev x11-apps && \
        apt-get clean && \
        apt-get autoremove -y --purge && \
            rm -rf /var/lib/apt/lists/*    
    COPY --from=build /usr/local/apr /usr/local/apr
  1. When you invoke java to run your jar, set your library path:

    ENTRYPOINT ["java","-Djava.library.path=/usr/local/apr/lib","-jar","app.jar"]

The app now starts and reports the proper libraries:

org.apache.catalina.core.AprLifecycleListener - Loaded Apache Tomcat Native library [1.2.31] using APR version [1.7.0].
Dharman
  • 30,962
  • 25
  • 85
  • 135