Multistage Dockerfiles for Quarkus

New Quarkus applications can be created in several ways, for example via CLI or the Start Coding page. Since applications are usually run in containers, Dockerfiles are created automatically. However they assume, that the code has already been built. This article describes how to build the code and the image together.

An easy way to create the Quarkus applications is to use the Start Coding page:

Executing the Maven build process in a container has several advantages. For example when developing locally, you don’t need to install specific Maven versions locally and all developers of your team are using the exact same build process.

Docker and other container technologies provide the ability to do multi-stage builds.

Here is how this can be done for Quarkus applications. Let’s assume you run Quarkus in the JVM mode. A Dockerfile ‘Dockerfile.jvm’ is created automatically.

All you need to do is to insert the Maven build at the top and refer to the generated files at the bottom via ‘–from=BUILD’. Here is the new Dockerfile, called ‘Dockerfile.jvm-multi’.

FROM adoptopenjdk/maven-openjdk11 as BUILD
COPY src /usr/src/app/src
COPY ./pom.xml /usr/src/app
WORKDIR /usr/src/app
RUN mvn package


ARG JAVA_PACKAGE=java-11-openjdk-headless


RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \
    && microdnf update \
    && microdnf clean all \
    && mkdir /deployments \
    && chown 1001 /deployments \
    && chmod "g+rwX" /deployments \
    && chown 1001:root /deployments \
    && curl${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION} -o /deployments/ \
    && chown 1001 /deployments/ \
    && chmod 540 /deployments/ \
    && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/

ENV JAVA_OPTIONS=" -Djava.util.logging.manager=org.jboss.logmanager.LogManager"

COPY --from=BUILD /usr/src/app/target/lib/* /deployments/lib/
COPY --from=BUILD /usr/src/app/target/*-runner.jar /deployments/app.jar

USER 1001

ENTRYPOINT [ "/deployments/" ]

Before building the image, comment out the ‘*’ line in .dockerignore.


Execute these commands to build and run your Quarkus application.

docker build -f src/main/docker/Dockerfile.jvm-multi -t quarkus/code-with-quarkus-jvm .
docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm
open http://localhost:8080/resteasy/hello