I have to add a custom root certificate to the Java trust store inside a docker environment. So I added the following command to my dockerfile:
RUN $JAVA_HOME/bin/keytool -import -file /opt/custom/certs/mycert.pem -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -trustcacerts -storepass changeit -noprompt
I get the following output when building the docker image:
Step 10/10 : RUN $JAVA_HOME/bin/keytool -import -file /opt/custom/certs/mycert.pem -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -trustcacerts -storepass changeit -noprompt
---> Running in cbc2a547797e
Certificate was added to keystore
keytool error: java.io.FileNotFoundException: /opt/java/openjdk/jre/lib/security/cacerts (No such file or directory)
The command '/bin/sh -c $JAVA_HOME/bin/keytool -import -file /opt/custom/certs/mycert.pem -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -trustcacerts -storepass changeit -noprompt' returned a non-zero code: 1
I'm baffled by the following facts:
Certificate was added to keystore seems to indicate a successful execution of keytoolkeytool error and a non-zero return-code, so no successWhat I've checked:
%JAVA_HOME seems to be available, as the error message displays the correct pathRUN command, then issue the exact same command inside the docker container, it works perfectly/bin/sh as the shell to make sure it's not the shell - workedNow I don't have any more ideas how to track this issue down.
It is probably a permission issue, what I'm guessing is that the base image you use changed the user from root and you need to be root to access the file. You should be able to do the following :
USER root
RUN $JAVA_HOME/bin/keytool -import -file /opt/custom/certs/mycert.pem -alias mycert -keystore $JAVA_HOME/jre/lib/security/cacerts -trustcacerts -storepass changeit -noprompt
USER originaluser
You can find the original user by using:
docker history yourbaseimagename:tag
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With