【发布时间】:2020-12-15 07:15:59
【问题描述】:
我正在尝试使用 Docker 创建 GraalVM 本机映像。我创建了一个 Micronaut 项目,并成功创建了一个 jar 应用程序并在 docker 中运行它;我也用这个 jar 文件创建了一个 GraalVM 原生镜像,现在可以运行这个应用程序,但是我需要在 docker 中运行一个 graalvm 原生镜像,在论坛中寻找答案我发现有必要构建原生docker里面的图片,所以我尝试了这个Dockerfile:
# use graalvm image
# replace the occurences of "product" with you jar name
FROM openjdk:8u171-alpine3.7
# expose your port, 8080 fo Micronaut applicatoin
EXPOSE 8080
# copy the fat jar
COPY build/libs/*-all.jar products.jar
# create the reflection configuration file generated by Micronaut
# for other frameworks you need to construct the file yourself
ADD . build
#RUN java -cp products.jar io.micronaut.graal.reflect.GraalClassLoadingAnalyzer
# run the native image compiler, you should already know the command arguments
# if you're not running micronaut
ENV PATH=PATHTOGRAALVM/graalvm-ce-java8-20.3.0/bin:$PATH
ENV JAVA_HOME=PATHTOGRAALVM/graalvm-ce-java8-20.3.0
CMD native-image --no-server \
--class-path products.jar \
-H:ReflectionConfigurationFiles=build/reflect.json \
-H:EnableURLProtocols=http \
-H:IncludeResources="logback.xml|application.yml|META-INF/services/*.*" \
-H:Name=products \
-H:Class=products.Application \
-H:+ReportUnsupportedElementsAtRuntime \
-H:+AllowVMInspection \
--rerun-class-initialization-at-runtime='sun.security.jca.JCAUtil$CachedSecureRandomHolder,javax.net.ssl.SSLContext' \
--delay-class-initialization-to-runtime=io.netty.handler.codec.http.HttpObjectEncoder,io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,io.netty.handler.ssl.util.ThreadLocalInsecureRandom
# the native command will be used to run the application
CMD ./products
而且它不会抛出任何异常或其他东西,所以我尝试用这个来运行我的 docker:
docker build --tag="products-with-graavm" .
docker run -d -p 8080:8080 products-with-graavm
但它什么也没做,我的应用程序没有运行,我的 Dockerfile 有问题还是我需要添加其他配置来创建我的本机映像?谢谢。
【问题讨论】:
-
你能检查一下是否创建了native-image吗?
-
嗨,我已经在 docker 中创建了本机映像,我删除了本机映像命令行中的一些行,这些行在创建本机映像时会引发异常。谢谢
标签: image docker native micronaut graalvm