我正在尝试用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出了问题,还是我需要添加其他配置来创建我的本机镜像?谢谢。
发布于 2020-12-23 03:33:55
我已经在docker中创建了我的本机映像,我删除了我的本机映像命令行中的一些行,这些行在创建本机映像时抛出了一个异常。这几行代码试图查找一些不在该位置的文件。此外,我还删除了旧版本GraalVM中的一些行。这些代码行如下:
-H:ReflectionConfigurationFiles=build/reflect.json \
-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谢谢。
https://stackoverflow.com/questions/65301509
复制相似问题