The English version of quarkus.io is the official project site. Translated sites are community supported on a best-effort basis.

Quarkus运行时基础镜像

To ease the containerization of native executables, Quarkus provides a base image providing the requirements to run these executables. The quarkus-micro-image:2.0 image is:

  • 小的 (基于 ubi8-micro )

  • 专为容器而设计的

  • 包含正确的依赖项(glibc、libstdc++、zlib)

  • 支持upx压缩的可执行文件(更多相关细节在 启用压缩文档 中)

使用此基础镜像

在你的 Dockerfile 中,只需使用:

FROM quay.io/quarkus/quarkus-micro-image:2.0
WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
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/ubi8/ubi-minimal:8.9 as BUILD
RUN microdnf install freetype

# Second stage - copy the dependencies
FROM quay.io/quarkus/quarkus-micro-image:2.0
COPY --from=BUILD \
   /lib64/libfreetype.so.6 \
   /lib64/libbz2.so.1 \
   /lib64/libpng16.so.16 \
   /lib64/

WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
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/ubi8/ubi-minimal:8.9 as BUILD
RUN microdnf install freetype fontconfig

# Second stage - copy the dependencies
FROM quay.io/quarkus/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/libexpat.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 target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

替代方案 - 使用 ubi-minimal

If the micro image does not suit your requirements, you can use ubi8/ubi-minimal. It’s a bigger image, but contains more utilities and is closer to a full Linux distribution. Typically, it contains a package manager (microdnf), so you can install packages more easily.

要使用该基础镜像,使用以下 Dockerfile:

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.9
WORKDIR /work/
RUN chown 1001 /work \
    && chmod "g+rwX" /work \
    && chown 1001:root /work
COPY --chown=1001:root target/*-runner /work/application

EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

Related content