简体   繁体   English

在 distroless 环境中将可自定义的选项传递给 GraalVM 映像执行

[英]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.对于上下文,我正在构建一个 java 应用程序,该应用程序编译为在 Kubernetes 中的无发行版 docker 映像上运行的GraalVM本机映像。

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 .我一直在尝试做一些相当简单的事情并碰壁:我想通过-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.问题的出现是由于使用了 distroless 映像 - 它没有 bash ,因此ENTRYPOINT /application $OPTIONS不起作用。

Is there an environment variable GraalVM supports on its own, or any other way of setting this?是否有 GraalVM 本身支持的环境变量,或任何其他设置方式?

I dont want to:我不想:

I am not sure if it will work but please, try setting the JAVA_TOOL_OPTIONS environment variable to the desired value:我不确定它是否会起作用,但请尝试将JAVA_TOOL_OPTIONS环境变量设置为所需的值:

JAVA_TOOL_OPTIONS=-XmxNNN

From the documentation :文档中:

This environment variable allows you to specify the initialization of tools, specifically the launching of native or Java programming language agents using the -agentlib or -javaagent options.此环境变量允许您指定工具的初始化,特别是使用 -agentlib 或 -javaagent 选项启动本机或 Java 编程语言代理。 In the following example the environment variable is set so that the HPROF profiler is launched when > the application is started:在以下示例中,环境变量被设置,以便在应用程序启动时启动 HPROF 分析器:

$ export JAVA_TOOL_OPTIONS="-agentlib:hprof"

This variable can also be used to augment the command line with other options for diagnostic purposes.此变量还可用于使用其他选项扩充命令行以用于诊断目的。 For example, you can supply the -XX:OnError option to specify a script or command to be executed when a fatal error occurs.例如,您可以提供-XX:OnError选项来指定发生致命错误时要执行的脚本或命令。

The GraalVM documentation itself provides an example of use as well, although in a different context. GraalVM 文档本身也提供了一个使用示例,尽管在不同的上下文中。

You could use busybox to get a shell inside a distroless container:您可以使用busybox在 distroless 容器中获取 shell :

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 .您可以在此处找到此类Dockerfile的示例。

But I don't think this busybox shell is necessary needed.但我认为不需要这个busybox shell。

Altough ENTRYPOINT /application $OPTIONS does not work, this will work ENTRYPOINT ["myapp", "arguments"]尽管ENTRYPOINT /application $OPTIONS不起作用,但这将起作用ENTRYPOINT ["myapp", "arguments"]

Note that distroless images by default do not contain a shell.请注意,默认情况下 distroless 映像不包含 shell。 That means the Dockerfile ENTRYPOINT command, when defined, must be specified in vector form, to avoid the container runtime prefixing with a shell.这意味着 Dockerfile ENTRYPOINT 命令在定义时必须以向量形式指定,以避免容器运行时以 shell 为前缀。

source: github来源: github

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM