Quarkus Base Runtime Image
为了简化本机可执行文件的容器化,Quarkus 提供了一个基本映像,用于提供运行这些可执行文件的要求。quarkus-micro-image:2.0
映像是:
-
small (based on
ubi8-micro
) -
designed for containers
-
包含正确的一组依赖项(glibc、libstdc++、zlib)
-
支持 upx 压缩的可执行文件(有关 enabling compression documentation 的更多详细信息)
Table of Contents
Using the base image
在您的 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"]
Extending the image
您的应用程序可能还有其他要求。例如,如果您有一个需要 libfreetype.so
的应用程序,则需要将本机库复制到容器中。在这种情况下,您需要使用多阶段 dockerfile
来复制所需的库:
# First stage - install the dependencies in an intermediate container
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 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.10 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"]
Alternative - Using ubi-minimal
如果微型镜像不符合您的要求,可使用 ubi8/ubi-minimal,这是一个更大的镜像,但包含更多实用工具,并且更接近完整的 Linux 发行版。通常,它包含一个程序包管理器 (microdnf
),以便您可以更方便地安装程序包。
要使用此基础镜像,请使用以下 Dockerfile
:
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10
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"]