编辑此页面
Quarkus 基础运行时镜像
为了简化原生可执行文件的容器化,Quarkus 提供了一个基础镜像,其中包含了运行这些可执行文件所需的组件。ubi9-quarkus-micro-image:2.0
镜像是
-
小巧的 (基于
ubi9-micro
) -
专为容器设计
-
包含正确依赖集 (glibc, libstdc++, zlib)
-
支持 UPX 压缩的可执行文件 (更多详情请参阅 启用压缩文档)
使用基础镜像
在你的 Dockerfile
中,只需使用
FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0
WORKDIR /work/
COPY --chmod=0755 target/*-runner /work/application
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
扩展镜像
你的应用程序可能还有其他需求。例如,如果你的应用程序需要 libfreetype.so
,你需要将原生库复制到容器中。在这种情况下,你需要使用多阶段 dockerfile
来复制所需的库
# First stage - install the dependencies in an intermediate container
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5 as BUILD
RUN microdnf install freetype -y
# Second stage - copy the dependencies
FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0
COPY --from=BUILD \
/lib64/libfreetype.so.6 \
/lib64/libbz2.so.1 \
/lib64/libpng16.so.16 \
/lib64/
WORKDIR /work/
COPY --chmod=0755 target/*-runner /work/application
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
如果你需要访问完整的 AWT 支持,你需要的不仅仅是 libfreetype.so
,还需要字体和字体配置
# First stage - install the dependencies in an intermediate container
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5 as BUILD
RUN microdnf install freetype fontconfig -y
# Second stage - copy the dependencies
FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0
COPY --from=BUILD \
/lib64/libfreetype.so.6 \
/lib64/libgcc_s.so.1 \
/lib64/libbz2.so.1 \
/lib64/libpng16.so.16 \
/lib64/libm.so.6 \
/lib64/libbz2.so.1 \
/lib64/libuuid.so.1 \
/lib64/
COPY --from=BUILD \
/usr/lib64/libfontconfig.so.1 \
/usr/lib64/
COPY --from=BUILD \
/usr/share/fonts /usr/share/fonts
COPY --from=BUILD \
/usr/share/fontconfig /usr/share/fontconfig
COPY --from=BUILD \
/usr/lib/fontconfig /usr/lib/fontconfig
COPY --from=BUILD \
/etc/fonts /etc/fonts
WORKDIR /work/
COPY --chmod=0755 target/*-runner /work/application
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
替代方案 - 使用 ubi-minimal
如果微镜像不符合你的要求,你可以使用 ubi9-minimal。它是一个更大的镜像,但包含更多实用程序,并且更接近完整的 Linux 发行版。通常,它包含一个包管理器 (microdnf
),因此你可以更轻松地安装包。
要使用此基础镜像,请使用以下 Dockerfile
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
WORKDIR /work/
RUN chown 1001 /work \
&& chmod "g+rwX" /work \
&& chown 1001:root /work
COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
EXPOSE 8080
USER 1001
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]