I have a Spring Boot Java application, which I want to run inside a Docker container. The application communicates with another service on internal network over HTTPS, but when I run the Docker container, I get the following exception (cause by the HTTPS connection):
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I had the same exception on my dev machine as well, which I fixed using this tutorial.
What I tried
- Many advices pointed out that
DOCKER_CERT_PATH
variable needs to be correctly set, but when I rundocker-machine env default
, I see it pointed toC:\Users\username\.docker\machines\machine\default
. - I tried to get the certificate and put it to this folder using this advice
- I tried adding
-Dtrust_all_cert=true
Java option to disable certificate check - I tried to switch from
org.spotify.dockerfile-maven-plugin
toorg.spotify.docker-maven-plugin
with this settings - I followed this tutorial and managed to add the certficiate to
/etc/ssl/certs/java/cacerts
and also to/usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts
in the Docker image.
None of these solutions worked, unfortunatelly.
My question
What should I do to get rid of this exception?
My Dockerfile (after applying previous solutions)
FROM openjdk:8-jdk-alpine
# to enable file writes
VOLUME /tmp
ADD target/trip-force-0.1.0.jar app.jar
# java cacerts
COPY ./res/timur.domain.local.cer /timur.domain.local.cer
ENV CACERTS /etc/ssl/certs/java/cacerts
RUN keytool -noprompt -import -alias timur -keystore ${CACERTS} -file /timur.domain.local.cer
ENV JAVA_OPTS="-Dtrust_all_cert=true"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]
What finally did the trick was the solution, that I probable should have tried in the beginning, as it was what fixed the problem on my dev machine.
Using this tutorial (and downloading the InstallCert.java file from here) I just copied the generated
jssecacerts
file inside the Docker image using this command in the Dockerfile: