在docker alpine中没有使用jlink找到 Java命令



我正在使用jlink创建一个定制的JRE用于docker


FROM gradle:7.5.1-jdk17-jammy As build
WORKDIR /build
COPY my-source my-source
RUN cd my-source && gradle clean build
RUN jlink 
--module-path /... 
--add-modules ... 
--output jre-custom 
--strip-debug 
--no-header-files 
--no-man-pages 
--compress 2
FROM alpine:latest
WORKDIR /deployment
COPY --from=build /build/jre-custom jre-custom/
COPY --from=build /build/my-source/build/libs/*.jar build/app.jar
# ERROR at line bellow: /bin/sh: jre-custom/bin/java: not found
CMD ["jre-custom/bin/java","-jar","build/app.jar"] 

EXPOSE 3009

当我在alpine图像中运行jre-custom/bin/java -version时,我得到:

/bin/sh: jre-custom/bin/java: not found

alpine image中是否有需要安装的文件?

注意:我可以在第一阶段docker中成功运行jre-custom/bin/java -version

我已经得到了解决方案,将第一阶段的图像更改为alpine-based图像,如下所示

# using image on alpine-based
FROM gradle:7.5.1-jdk17-alpine As build
WORKDIR /build
COPY my-source my-source
# install required packages
RUN apk update && apk add gcompat binutils
RUN gradle -p my-source clean build
RUN jlink 
--module-path /opt/java/openjdk/jmods 
--add-modules $(jdeps --ignore-missing-deps --print-module-deps --multi-release 17 my-source/build/libs/*.jar ) 
--output jre-custom 
--strip-debug 
--no-header-files 
--no-man-pages 
--compress 2

# reduce image size a little bit more (-4MB)
RUN strip -p --strip-unneeded jre-custom/lib/server/libjvm.so && 
find jre-custom -name '*.so' | xargs -i strip -p --strip-unneeded {}
FROM alpine:latest
WORKDIR /deployment
COPY --from=build /build/jre-custom jre-custom/
COPY --from=build /build/my-source/build/libs/*.jar build/app.jar
CMD ["jre-custom/bin/java","-jar","build/app.jar"] 

EXPOSE 3009

相关内容

  • 没有找到相关文章

最新更新