如何在Docker中为Java应用程序添加HTTPSauthentication?

我有一个Java应用程序,使用证书保护HTTP API的POST请求。 当我第一次在本地运行时,出现以下exception:

I/O error on POST request for "https://... sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target 

为了解决这个问题,我从Firefox导出了证书,并执行以下操作:

 sudo keytool -import -alias example -keystore /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts -file /path/to/certificate.der 

重新启动,然后它的工作。

现在我想让应用程序在Docker上运行。 所以,就像我之前做的那样,我使用Spotify的docker -maven插件和openjdk作为基础镜像。 第一个错误再次出现,所以我尝试以相同的方式修复它。

插件用法:

 <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.13</version> <configuration> <useConfigFile>true</useConfigFile> <imageName>${project.artifactId}:${project.version}</imageName> <baseImage>openjdk:latest</baseImage> <imageTags> <imageTag>latest</imageTag> <imageTag>${project.version}</imageTag> </imageTags> <resources> <resource> <targetPath>/path/${project.artifactId}</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}-jar-with-dependencies.jar</include> </resource> <resource> <targetPath>/path/${project.artifactId}</targetPath> <directory>${project.basedir}</directory> <include>certificate.der</include> </resource> </resources> <runs> <run>$JAVA_HOME/bin/keytool -import -noprompt -trustcacerts -alias example -file /path/certificate.der -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit</run> <run>chmod 555 /path</run> <run>chmod 444 /path/${project.build.finalName}-jar-with-dependencies.jar</run> </runs> <entryPoint> ["java", "-jar", "/path/${project.build.finalName}-jar-with-dependencies.jar"] </entryPoint> </configuration> 

生成的Dockerfile是:

 FROM openjdk:latest ADD /path/application.jar /path/ ADD /path/certificate.der /path/ RUN $JAVA_HOME/bin/keytool -import -noprompt -trustcacerts -alias example -file /path/certificate.der -keystore $JAVA_HOME/jre/lib/security/cacerts -storepass changeit RUN chmod 555 /path RUN chmod 444 /path/application.jar ENTRYPOINT ["java", "-jar", "/path/application.jar"] 

问题不是固定的。 我运行docker和发布请求完成时,我有完全相同的错误,如果我没有在密钥库中的证书,我在开始时提到的。 此外,如果我检查密钥库,它有证书。

我错过了什么?

任何帮助表示赞赏:)