Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore the older native docker file using UBI minimal as base image #22617

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions docs/src/main/asciidoc/building-native-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
----
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you be more explicit? I have no idea what you're complaining about :).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dockerfile from docs/src/main/asciidoc/building-native-image.adoc (lines 506-512):

FROM <...>
WORKDIR /work/
COPY target/*-runner /work/application
RUN chmod 775 /work
EXPOSE 8080
CMD <...>

Dockerfile from docs/src/main/asciidoc/quarkus-runtime-base-image.adoc (lines 115-125):

FROM <...>
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 <...>

It looks like these commands target the same case, yet they are different. What I am curious about, is if it intentional, or not?


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

Expand Down
24 changes: 24 additions & 0 deletions docs/src/main/asciidoc/quarkus-runtime-base-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
----
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public class JibConfig {
public Optional<String> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
#
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down