dockerquarkusjava-19

How to build a quarkus docker image with JDK 19 and Virtual Thread support


I try to use Virtual Threads in a Quarkus application but cannot find a way to build a Quarkus Docker image with JDK19.

Local development works fine and application runs without problems. However, the official Red-Hat Docker images only support JDK17.

Tried to tune the official build image for JDK17 but without success.

How would you build a quarkus image with openjdk-19?


Solution

  • In case someone looks for a similar solution, this is how I solved the problem with a staged Docker build:

    # Use the official JDK 19 image as the base image for the build stage
    FROM openjdk:19-jdk AS build
    
    # Enable preview features
    ENV JAVA_OPTS="--enable-preview"
    
    # Set the working directory
    WORKDIR /app
    
    # Copy the Maven wrapper
    COPY mvnw .
    COPY .mvn .mvn
    
    # Copy the pom.xml file
    COPY pom.xml .
    
    ENV HTTP_PROXY="http://host.docker.internal:3128"
    ENV HTTPS_PROXY="http://host.docker.internal:3128"
    ENV http_proxy="http://host.docker.internal:3128"
    ENV https_proxy="http://host.docker.internal:3128"
    ENV MAVEN_OPTS="-Dhttp.proxyHost=host.docker.internal -Dhttp.proxyPort=3128 -Dhttps.proxyHost=host.docker.internal -Dhttps.proxyPort=3128 --enable-preview"
    
    # Download dependencies and cache them
    RUN ./mvnw dependency:go-offline -B
    
    # Copy the source code
    COPY ./src ./src
    
    # Compile and package the application
    RUN ./mvnw package -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -B -V
    
    
    # Use the official JDK 19 image as the base image for the runtime stage
    FROM openjdk:19-jdk AS runtime
    
    # Enable preview features
    ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager --enable-preview"
    
    # Set the working directory
    WORKDIR /app
    
    # Copy the build artifacts from the build stage
    #COPY --from=build /app/target/quarkus-app/quarkus-run.jar /app/app.jar
    COPY --from=build /app/target/quarkus-app/lib/ /app/lib/
    COPY --from=build /app/target/quarkus-app/*.jar /app/
    COPY --from=build /app/target/quarkus-app/app/ /app/app/
    COPY --from=build /app/target/quarkus-app/quarkus/ /app/quarkus/
    
    # Set the entrypoint and command to run the application
    ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar /app/quarkus-run.jar"]