Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 18 April 2021

Import self-signed certificate into Docker's JRE cacert

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:8
ADD ./target/sample_application.jar sample_application.jar
COPY ./src/main/resources/application.pem application.pem
RUN keytool -importcert -noprompt -alias sslAppCertificate -file application.pem -trustcacerts -keystore $JAVA_HOME/jre/lib/security/cacerts -storetype JKS -storepass changeit
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "sample_application.jar"]

Note: This application.pem file only contains certificate.

Share this Blog with yours Friends !!

1 comment:

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

    ReplyDelete