Issue
I'm working on a building a docker image. It basically uses the eclipse-temurin
.
The dockerfile does download some certs online and import into java based on if the java version is 8 or not.
Below is the Dockerfile
FROM eclipse-temurin:8
RUN curl -ksS https://myorg1.com/certs/root > Org1_CA.pem && \
curl -ksS https://myorg2.com/certs/root > Org2_CA.pem && \
openssl x509 -in Org1_CA.pem -inform PEM -out Org1_CA.crt && \
openssl x509 -in Org2_CA.pem -inform PEM -out Org2_CA.crt && \
cp Org1_CA.crt /usr/local/share/ca-certificates/Org1_CA.crt && \
cp Org2_CA.crt /usr/local/share/ca-certificates/Org2_CA.crt && \
update-ca-certificates
ARG BASE_TAG
RUN echo "BASE TAG is " ${BASE_TAG}
RUN set -eux; \
if [ "$BASE_TAG" = "temurin-8-jammy" ] \
then \
mkdir -p "$JAVA_HOME""$JRE_PREFIX"/lib/security && \
keytool -import -alias Org1Cert -keystore "$JAVA_HOME""$JRE_PREFIX"/lib/security/cacerts -file /usr/local/share/ca-certificates/Org1_CA.crt -storepass changeit -noprompt && \
keytool -import -alias Org2Cert -keystore "$JAVA_HOME""$JRE_PREFIX"/lib/security/cacerts -file /usr/local/share/ca-certificates/Org2_CA.crt -storepass changeit -noprompt \
else \
mkdir -p "$JAVA_HOME"/conf/security && \
keytool -importcert -alias Org1Cert -keystore "$JAVA_HOME"/conf/security/cacerts -file /usr/local/share/ca-certificates/Org1_CA.crt -storetype PKCS12 -storepass changeit -noprompt && \
keytool -importcert -alias Org2Cert -keystore "$JAVA_HOME"/conf/security/cacerts -file /usr/local/share/ca-certificates/Org2_CA.crt -storetype PKCS12 -storepass changeit -noprompt \
fi
RUN echo "DONE"
The docker build command that I'm using is -
docker build . -t j8 --build-arg BASE_IMAGE=temurin-8-jammy --build-arg JRE_PREFIX=/jre
But I'm getting error
ERROR: failed to solve: process "/bin/sh -c did not complete successfully: exit code: 2"
When I run individual commands it is working fine but when I make it into single RUN command with if else it is giving error.
How can I fix this error?
Solution
There has to be a ;
before then
, else
, and fi
.
if something; then this; else that; fi
Like this:
RUN set -eux; \
if [ "$BASE_TAG" = "temurin-8-jammy" ] ; \
then \
mkdir -p "$JAVA_HOME""$JRE_PREFIX"/lib/security && \
keytool -import -alias Org1Cert -keystore "$JAVA_HOME""$JRE_PREFIX"/lib/security/cacerts -file /usr/local/share/ca-certificates/Org1_CA.crt -storepass changeit -noprompt && \
keytool -import -alias Org2Cert -keystore "$JAVA_HOME""$JRE_PREFIX"/lib/security/cacerts -file /usr/local/share/ca-certificates/Org2_CA.crt -storepass changeit -noprompt; \
else \
mkdir -p "$JAVA_HOME"/conf/security && \
keytool -importcert -alias Org1Cert -keystore "$JAVA_HOME"/conf/security/cacerts -file /usr/local/share/ca-certificates/Org1_CA.crt -storetype PKCS12 -storepass changeit -noprompt && \
keytool -importcert -alias Org2Cert -keystore "$JAVA_HOME"/conf/security/cacerts -file /usr/local/share/ca-certificates/Org2_CA.crt -storetype PKCS12 -storepass changeit -noprompt; \
fi
Answered By - KamilCuk Answer Checked By - Timothy Miller (WPSolving Admin)