ClassNotFoundException while starting a container

Hi,
I am trying to start a Docker container based on the image created by below mentioned docker file. The service useses Consul libraries.
When starting the contained, I am getting below mentioned ClassNotFoundException. I can confirm that the Classpath is already set to valid jar in the container.
It would be very helpful if someone can guide me through.
Regards.

DockerFile
FROM osvc-docker-local.dockerhub-den.oraclecorp.com/java/serverjre:latest
MAINTAINER Brandon Johnson “brandon.johnson@oracle.com
ADD gatekeeper-oci-1.0.0.0.tar /
ENV CLASSPATH /gatekeeper-oci-1.0.0.0/lib/consul-client-1.4.0.jar
ENTRYPOINT [“java”, “-Xmx512m”, “-Xms512m”, “-XX:+UseG1GC”, “-XX:MaxGCPauseMillis=100”, “-jar”, “/gatekeeper-oci-1.0.0.0/lib/gatekeeper-1.0.0.0.jar”]
EXPOSE 7001
ADD gatekeeper-oci-filters-1.0.0.0.tar /
ENTRYPOINT ["/gatekeeper-oci-filters-1.0.0.0/bin/gatekeeper-ingress-filters"]

Exception
java.lang.NoClassDefFoundError: com/orbitz/consul/Consul
at com.xxxxx.OSvC.xxxxx.gateway.GatewayModule.configure(GatewayModule.java:66)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:340)
at com.google.inject.spi.Elements.getElements(Elements.java:110)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:138)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:99)
at com.google.inject.Guice.createInjector(Guice.java:84)
at com.netflix.governator.LifecycleInjectorCreator.createInjector(LifecycleInjectorCreator.java:100)
at com.netflix.governator.LifecycleInjectorCreator.createInjector(LifecycleInjectorCreator.java:38)
at com.netflix.governator.InjectorBuilder.createInjector(InjectorBuilder.java:209)
at com.netflix.governator.InjectorBuilder.createInjector(InjectorBuilder.java:230)
at com.xxxxx.OSvC.xxxxx.gateway.Bootstrap.start(Bootstrap.java:38)
at com.xxxxx.OSvC.xxxxx.gateway.Bootstrap.main(Bootstrap.java:21)
Caused by: java.lang.ClassNotFoundException: com.orbitz.consul.Consul
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

Env Variables
C:\Users\tussinha>docker exec -it 591437cbb60e env
PATH=/usr/java/jdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=591437cbb60e
TERM=xterm
LANG=en_US.UTF-8
JAVA_VERSION=1.8.0_261
JAVA_HOME=/usr/java/jdk-8
CLASSPATH=/xxxxx-xxx-1.0.0.0/lib/consul-client-1.4.0.jar
HOME=/root

It’s a bit difficult to help, I don’t find a documentation for the serverjre image anywhere. One thing that is not clear is what the WORKDIR in the running container is. Maybe you should explicitly create an application folder and set it as workdir, so you know where you are. Then you say that the classpath points to a valid jar file. Just I don’t see where file consul-client-1.4.0.jar in folder /gatekeeper-oci-1.0.0.0/lib/ comes from. You derive directly from Oracle’s serverjre and just copy gatekeeper-oci-1.0.0.0.tar to /. How did you check that the jar file is there?

Try to add , "-cp","/gatekeeper-oci-1.0.0.0/lib/*.jar" to your entrypoint command to include all jars in the lib folder and loose the CLASSPATH env.

Also with ENTRYPOINT the last declaration is the one beeing used. Having two of them in a Dockerfile has no value.

My bad, I had the first entrypoint in mind, that started with the “java” cmd when I suggested to add -cp, which is a parameter to the java executable.

Honestly, I have no idea what your second entypoint (the one u used to add the -cp paramter) does, though your previous error message indicated that the used classpath does not cover all required jar’s.

Can you share the content of /gatekeeper-oci-filters-1.0.0.0/bin/gatekeeper-ingress-filters?

Hi,
As I mentioned in the previous response.
I have removed the second entrypoint and am using only one entry point ENTRYPOINT ["/gatekeeper-oci-1.0.0.0/bin/gatekeeper", “-cp”, “/gatekeeper-oci-1.0.0.0/lib/*.jar”]

The above response content is all I have in my latest DockerFile,

FROM xxx/java/serverjre:latest
MAINTAINER Tushar Sinha “xxxxxx”
ADD gatekeeper-oci-1.0.0.0.tar /
ENTRYPOINT ["/gatekeeper-oci-1.0.0.0/bin/gatekeeper", “-cp”, “/gatekeeper-oci-1.0.0.0/lib/*.jar”]
EXPOSE 7001
ADD gatekeeper-oci-filters-1.0.0.0.tar /

I sense a tremendous amount of confusion :slight_smile:

Please remove the -cp option and its parameter again. like I already wrote this ONLY would have worked for the entrypoint that started with the java command. You ignored this from my last post.

Also you ignored that I asked to see the entrypoint script and pasted your Dockerfile again. We already know the entrypoint declaration in the Dockerfile. What we don’t know is the content of your entrypoint script.