Home > Software design >  Override ENTRYPOINT configuration in Micronaut Gradle Dockerfile
Override ENTRYPOINT configuration in Micronaut Gradle Dockerfile

Time:01-05

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?

CodePudding user response:

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"]
  •  Tags:  
  • Related