javadockergraalvmdistroless

Passing customizable options to a GraalVM image execution in a distroless environment


For context, I'm building a java application compiled to GraalVM native image running on a distroless docker image in Kubernetes.

I've been trying to do something rather simple and hit a wall: I'd like to set custom heap size limits per environment via -XmxNNN. To do that, the options with which I'd like to run the application would be held in an environment variable. The problem arises due to the usage of a distroless image - which doesn't have bash and so ENTRYPOINT /application $OPTIONS doesn't work.

Is there an environment variable GraalVM supports on its own, or any other way of setting this?

I dont want to:


Solution

  • You could use busybox to get a shell inside a distroless container:

    FROM gcr.io/distroless/base
    
    ...
    
    COPY --from=amd64/busybox:1.31.1 /bin/busybox /busybox/busybox
    RUN ["/busybox/busybox", "--install", "/bin"]
    
    CMD ["/bin/sh", "-c", "java -version"]
    

    You can find an example to this kind of Dockerfile here.

    But I don't think this busybox shell is necessary needed.

    Altough ENTRYPOINT /application $OPTIONS does not work, this will work ENTRYPOINT ["myapp", "arguments"]

    Note that distroless images by default do not contain a shell. That means the Dockerfile ENTRYPOINT command, when defined, must be specified in vector form, to avoid the container runtime prefixing with a shell.

    source: github