Search code examples
javadockermavenbuildpackjib

Pass parameters to my application in a image done with JIB


I would like to optimize my docker image using jib. I have been using a Dockerfile like this:

FROM openjdk:8-jdk
ARG NAME
ADD $NAME app.jar
VOLUME /tmp
VOLUME /certificates

ENTRYPOINT exec java $JAVA_OPTIONS -jar app.jar

Now I am creating the image with mvn compile jib:dockerBuild but would like to know how to add the JAVA_OPTIONS to my application as I did in the past in the ENTRYPOINT of my old Dockerfile.

Thanks in advance


Solution

  • I assume that you are dynamically supplying an environment variable for some Java flags at runtime and you want your JVM to pick up the flags at runtime. (If your intention is to statically set the flags and bake them into the container image at image build-time, it should be done in a different way.)

    Just set the desired flags in JAVA_TOOL_OPTIONS or JDK_JAVA_OPTIONS if Java 9+. Your JVM will automatically pick them up (although not all Java flags may not be supported with JAVA_TOOL_OPTIONS).