title: SunCertPathBuilderException when running a Java application in Docker Toolbox
body: <p>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):</p>
  
  <pre><code>Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  </code></pre>
  
  <p>I had the same exception on my dev machine as well, which I fixed using <a href="https://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/" rel="nofollow noreferrer">this tutorial</a>.</p>
  
  <p><strong>What I tried</strong></p>
  
  <ul>
  <li>Many advices pointed out that <code>DOCKER_CERT_PATH</code> variable needs to be correctly set, but when I run <code>docker-machine env default</code>, I see it pointed to <code>C:\Users\username\.docker\machines\machine\default</code>.</li>
  <li>I tried to get the certificate and put it to this folder using <a href="https://superuser.com/a/641396">this advice</a></li>
  <li>I tried adding <code>-Dtrust_all_cert=true</code> Java option to disable certificate check</li>
  <li>I tried to switch from <code>org.spotify.dockerfile-maven-plugin</code> to <code>org.spotify.docker-maven-plugin</code> with <a href="https://stackoverflow.com/questions/34815411/docker-maven-plugin-clientprotocolexception-windows-10-using-docker-toolbox/41621300#41621300">this settings</a></li>
  <li>I followed <a href="https://adamtuttle.codes/TIL-adding-a-jvm-ssl-cert-docker/" rel="nofollow noreferrer">this tutorial</a> and managed to add the certficiate to <code>/etc/ssl/certs/java/cacerts</code> and also to <code>/usr/lib/jvm/java-1.8-openjdk/jre/lib/security/cacerts</code> in the Docker image.</li>
  </ul>
  
  <p>None of these solutions worked, unfortunatelly.</p>
  
  <p><strong>My question</strong></p>
  
  <p>What should I do to get rid of this exception?</p>
  
  <p><strong>My Dockerfile (after applying previous solutions)</strong></p>
  
  <pre><code>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" ]
  </code></pre>