I am using azul/zulu-openjdk-distroless:17.0.6 image and want to execute the java command with parameters but it fails at the runtime
Here is my docker image:
FROM alpine:3.17.3 as build-env
ARG DATADOG_VERSION=1.8.3
RUN wget https://github.com/DataDog/dd-trace-java/releases/download/v${DATADOG_VERSION}/dd-java-agent-${DATADOG_VERSION}.jar
FROM azul/zulu-openjdk-distroless:17.0.6
COPY --from=build-env dd-java-agent-*.jar javaagent.jar
COPY *-app/target/*.jar app.jar
ARG JAVA_AGENT="-javaagent:javaagent.jar"
CMD ["${JAVA_AGENT}", "-jar", "app.jar"]
I get the following error when I run it:
Error: Could not find or load main class ${JAVA_AGENT}
Caused by: java.lang.ClassNotFoundException: ${JAVA_AGENT}
I tried with ENV
instead of ARG
and ENTRYPOINT
instead of CMD
, none of them worked. I tried without the []
brackets but then I get another error:
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory: unknown.
If I put the value directly like CMD ["-javaagent:javaagent.jar", "-jar", "app.jar"]
then it works but the container runs in a pipeline where the variable's value is coming from so I want to use variable. I would also use another one for JAVA_OPTS which is much harder to hardcode.
Is there any possibility to solve it somehow or the only solution is to hardcode the parameters?