In order to import ssl certificate into Java Security cacert from Docker file use below keytool command in Docker file.
First we need to copy the required file(.pem or .crt) into Docker with the help of below COPY commands.
To copy the .pem file in Docker image, add below command into Docker file.
COPY ./src/main/resources/application.pem application.pem
To copy the .crt file in Docker image, add below command into Docker file.
COPY ./src/main/resources/application_CA.crt application_CA.crt
Below keytool command copy the ssl certificate into Docker Java cacert folder.
<Alias Name>: Certificate Alias Name
<.crt file or .pem file Path>: Certificate file Name with path or .pem file name with path
RUN keytool -importcert -noprompt -alias <Alias Name> -file <.crt file or .pem file> -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storetype JKS -storepass changeit
Sample Docker File.
FROM openjdk:8ADD ./target/sample_application.jar sample_application.jarCOPY ./src/main/resources/application.pem application.pemRUN keytool -importcert -noprompt -alias sslAppCertificate -file application.pem -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storetype JKS -storepass changeitEXPOSE 8080ENTRYPOINT ["java", "-jar", "sample_application.jar"]
Note: This application.pem file only contains certificate.

Thank you, for this information
ReplyDeleteThe blog is very informative. looking forward to reading more from you thank you
cbse class 10 tuition