1

I'm running a Micronaut application as a Docker container.

At runtime in Kuberentes there will be a JAVA_OPTS environment variable with certaint values, e.g.: -XX:MaxRAMPercentage=45.0

When executing ./gradlew dockerBuild I can see the following Docker layer:

Step 7/7 : ENTRYPOINT ["java", "-jar", "/home/app/application.jar"]

Following the documentation I tried to add a reference to JAVA_OPTS:

build.gradle.kts

    dockerfile {
        args("\$JAVA_OPTS")
    }

Docker build log:

Step 7/7 : ENTRYPOINT ["java", "$JAVA_OPTS", "-jar", "/home/app/application.jar"]

The problem with this, is that the container wont's start, since $JAVA_OPTS won't be replaced by the env variable value. This happens because it is using the exec form of the ENTRYPOINT.

Is there a way to override or tune the ENTRYPOINT so that env vars are evaluated?

codependent
  • 23,193
  • 31
  • 166
  • 308
  • As demonstrated in the other question you linked, you could `ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /home/app/application.jar"]` – Zeitounator Jan 04 '22 at 14:11
  • 1
    The question is how to configure Micronaut to change the entrypoint – codependent Jan 04 '22 at 14:20
  • Overflying the documentation you linked, I came across the following link that might be clearer to you than to myself: https://github.com/bmuschko/gradle-docker-plugin/blob/763dc3e6117a6c486893ec5fc1a6275eb06ae9d3/src/main/groovy/com/bmuschko/gradle/docker/tasks/image/Dockerfile.groovy#L753 – Zeitounator Jan 04 '22 at 14:29
  • I think that won't work, the documentation shows an example: `The produced instruction looks as follows: ENTRYPOINT ["top", "-b"]` – codependent Jan 04 '22 at 14:51
  • ...`entryPoint('sh', '-c', 'java $JAVA_OPTS -jar /home/app/application.jar')` => `ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /home/app/application.jar"]` ??? – Zeitounator Jan 04 '22 at 14:54
  • Oops, you're right, that'll work. I you add that info as an answer I'll be glad to accept it. Thanks! – codependent Jan 04 '22 at 15:01

1 Answers1

1

Following the link in your documentation, it looks like you can do something like the following to override the entrypoint according to your requirement to interpret the env var in the command:

entryPoint('sh', '-c', 'java $JAVA_OPTS -jar /home/app/application.jar')

It should translate to the following in the generated Dockerfile:

ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /home/app/application.jar"]
Zeitounator
  • 38,476
  • 7
  • 53
  • 66