From 5ef8c8f14a80347ea2795cb962e3141f95b71f19 Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Tue, 4 Jan 2022 15:40:02 +0100 Subject: [PATCH] Restore the older native docker file using UBI minimal as base image --- .../main/asciidoc/building-native-image.adoc | 21 +++++++++++-- .../asciidoc/quarkus-runtime-base-image.adoc | 24 +++++++++++++++ .../image/jib/deployment/JibConfig.java | 5 +++- .../main/docker/Dockerfile.tpl.qute.native | 2 +- .../docker/Dockerfile.tpl.qute.native-micro | 30 +++++++++++++++++++ .../quarkus/tooling/dockerfiles/codestart.yml | 2 ++ .../QuarkusCodestartGenerationTest.java | 12 ++++++-- 7 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native-micro diff --git a/docs/src/main/asciidoc/building-native-image.adoc b/docs/src/main/asciidoc/building-native-image.adoc index aae51d6fe5236..62bdcac770fb4 100644 --- a/docs/src/main/asciidoc/building-native-image.adoc +++ b/docs/src/main/asciidoc/building-native-image.adoc @@ -441,7 +441,7 @@ If one of those extensions is present, then creating a container image for the n See the xref:container-image.adoc[Container Image guide] for more details. -=== Manually +=== Manually using the micro base image You can run the application in a container using the JAR produced by the Quarkus Maven Plugin. However, in this section we focus on creating a container image using the produced native executable. @@ -454,7 +454,7 @@ we will instruct the Maven build to produce an executable by leveraging a contai The produced executable will be a 64 bit Linux executable, so depending on your operating system it may no longer be runnable. However, it's not an issue as we are going to copy it to a container. -The project generation has provided a `Dockerfile.native` in the `src/main/docker` directory with the following content: +The project generation has provided a `Dockerfile.native-micro` in the `src/main/docker` directory with the following content: [source,dockerfile] ---- @@ -497,6 +497,23 @@ And finally, run it with: docker run -i --rm -p 8080:8080 quarkus-quickstart/getting-started ---- +=== Manually using the minimal base image + +The project generation has also provided a `Dockerfile.native` in the `src/main/docker` directory with the following content: + +[source,dockerfile] +---- +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5 +WORKDIR /work/ +COPY target/*-runner /work/application +RUN chmod 775 /work +EXPOSE 8080 +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] +---- + +The UBI minimal image is bigger than the micro one mentioned above. +It contains more utilities such as the `microdnf` package manager. + [#multistage-docker] === Using a multi-stage Docker build diff --git a/docs/src/main/asciidoc/quarkus-runtime-base-image.adoc b/docs/src/main/asciidoc/quarkus-runtime-base-image.adoc index e2b5b7dbac60d..ea888110d2317 100644 --- a/docs/src/main/asciidoc/quarkus-runtime-base-image.adoc +++ b/docs/src/main/asciidoc/quarkus-runtime-base-image.adoc @@ -100,3 +100,27 @@ EXPOSE 8080 CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] ---- + +== Alternative - Using ubi-minimal + +If the micro image does not suit your requirements, you can use https://catalog.redhat.com/software/containers/ubi8/ubi-minimal/5c359a62bed8bd75a2c3fba8[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. + + +To use this base image, use the following `Dockerfile`: + +[source, dockerfile] +---- +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5 +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"] +---- \ No newline at end of file diff --git a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java index 923f8b6de9581..95ad72193951a 100644 --- a/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java +++ b/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/JibConfig.java @@ -23,7 +23,10 @@ public class JibConfig { public Optional baseJvmImage; /** - * The base image to be used when a container image is being produced for the native binary build + * The base image to be used when a container image is being produced for the native binary build. + * The default is "quay.io/quarkus/quarkus-micro-image". You can also use + * "registry.access.redhat.com/ubi8/ubi-minimal" which is a bigger base image, but provide more built-in utilities + * such as the microdnf package manager. */ @ConfigItem(defaultValue = "quay.io/quarkus/quarkus-micro-image:1.0") public String baseNativeImage; diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native index 7e2697acbb008..5f84d15ec5541 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native @@ -1,5 +1,5 @@ #### -# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. # # Before building the container image run: # diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native-micro b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native-micro new file mode 100644 index 0000000000000..1209d56d5c35c --- /dev/null +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/base/src/main/docker/Dockerfile.tpl.qute.native-micro @@ -0,0 +1,30 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# {buildtool.cli} {buildtool.cmd.package-native} +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/{project.artifact-id} . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/{project.artifact-id} +# +### +FROM {dockerfile.native-micro.from} +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root {buildtool.build-dir}/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml index b8c8d3a5c29d6..2f307d8f7ad3b 100644 --- a/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml +++ b/independent-projects/tools/base-codestarts/src/main/resources/codestarts/quarkus/tooling/dockerfiles/codestart.yml @@ -5,4 +5,6 @@ language: data: dockerfile: native: + from: registry.access.redhat.com/ubi8/ubi-minimal:8.5 + native-micro: from: quay.io/quarkus/quarkus-micro-image:1.0 diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java index 248c1f4529d72..8ce80a485a7ba 100644 --- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java +++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java @@ -286,10 +286,14 @@ private void checkDockerfilesWithMaven(Path projectDir) { .satisfies(checkContains("EXPOSE 8080")) .satisfies(checkContains("USER 185")) .satisfies(checkContains("ENTRYPOINT [ \"java\", \"-jar\", \"/deployments/quarkus-run.jar\" ]")); - assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists() + assertThat(projectDir.resolve("src/main/docker/Dockerfile.native-micro")).exists() .satisfies(checkContains("./mvnw package -Pnative")) .satisfies(checkContains("quay.io/quarkus/quarkus-micro-image:1.0")) .satisfies(checkContains("CMD [\"./application\", \"-Dquarkus.http.host=0.0.0.0\"]")); + assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists() + .satisfies(checkContains("./mvnw package -Pnative")) + .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal")) + .satisfies(checkContains("CMD [\"./application\", \"-Dquarkus.http.host=0.0.0.0\"]")); } private void checkDockerfilesWithGradle(Path projectDir) { @@ -306,10 +310,14 @@ private void checkDockerfilesWithGradle(Path projectDir) { .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal:8.4")) .satisfies(checkContains("ARG JAVA_PACKAGE=java-11-openjdk-headless")) .satisfies(checkContains("ENTRYPOINT [ \"/deployments/run-java.sh\" ]")); - assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists() + assertThat(projectDir.resolve("src/main/docker/Dockerfile.native-micro")).exists() .satisfies(checkContains("./gradlew build -Dquarkus.package.type=native")) .satisfies(checkContains("quay.io/quarkus/quarkus-micro-image:1.0")) .satisfies(checkContains("CMD [\"./application\", \"-Dquarkus.http.host=0.0.0.0\"]")); + assertThat(projectDir.resolve("src/main/docker/Dockerfile.native")).exists() + .satisfies(checkContains("./gradlew build -Dquarkus.package.type=native")) + .satisfies(checkContains("registry.access.redhat.com/ubi8/ubi-minimal")) + .satisfies(checkContains("CMD [\"./application\", \"-Dquarkus.http.host=0.0.0.0\"]")); } private void checkConfigProperties(Path projectDir) {