Create a docker image with WildFly and a Jakarta EE application deployed

Create a docker image with WildFly and a Jakarta EE application deployed

deploy a Jakarta EE application on WildFly and create a Docker image

In this article we show HOW-TO create a docker image containing WildFly with a Java application deployed in it; the docker image is ready to be run in OpenShift, Kubernetes or just locally with docker or podman;

The process is broken to pieces in order to provide a deep understanding of all the moving parts;

The first 3 steps are not meant to be executed during the usual development life-cycle: their goal is just to show how those artifacts are produced;

  1. wildfly-preview-cloud-galleon-pack : provides e.g. health endpoint

    git clone git@github.com:wildfly-extras/wildfly-cloud-galleon-pack.git 
    cd wildfly-cloud-galleon-pack
    mvn install -DskipTests
    --> .m2/repository/org/wildfly/cloud/wildfly-preview-cloud-galleon-pack/2.0.0.Alpha5-SNAPSHOT
    
  2. wildfly : the "Jakarta EE 10" server to run our application

    git clone git@github.com:wildfly/wildfly.git
    cd wildfly
    mvn install -DskipTests
    --> .m2/repository/org/wildfly/wildfly-galleon-pack/27.0.0.Alpha5-SNAPSHOT
    --> .m2/repository/org/wildfly/wildfly-preview-feature-pack/27.0.0.Alpha5-SNAPSHOT
    
  3. wildfly-maven-plugin : the maven plugin capable of assembling server+application from wildfly-galleon-pack and wildfly-preview-cloud-galleon-pack

    git clone git@github.com:wildfly/wildfly-maven-plugin.git
    cd wildfly-maven-plugin
    mvn install -DskipTests
    --> .m2/repository/org/wildfly/plugins/wildfly-maven-plugin/4.0.0.Beta4-SNAPSHOT
    
  4. wildfly-s2itest-app : the "Jakarta EE 10" application

    git clone git@github.com:wildfly/wildfly-s2i.git
    cd wildfly-s2i/test/test-app
    

Adjust the wildfly-maven-plugin configuration in order to use the versions we just built of the following artifacts:

  • wildfly-maven-plugin
  • wildfly-preview-feature-pack
  • wildfly-preview-cloud-galleon-pack
    <plugin>
      <groupId>org.wildfly.plugins</groupId>
      <artifactId>wildfly-maven-plugin</artifactId>
      <version>4.0.0.Beta4-SNAPSHOT</version>
      <configuration>
          <!-- some tests check for the provisioned galleon layers -->
          <record-provisioning-state>true</record-provisioning-state>
          <feature-packs>
              <feature-pack>
                  <location>org.wildfly:wildfly-preview-feature-pack:27.0.0.Alpha5-SNAPSHOT</location>
              </feature-pack>
              <feature-pack>
                  <location>org.wildfly.cloud:wildfly-preview-cloud-galleon-pack:2.0.0.Alpha5-SNAPSHOT</location>
              </feature-pack>
          </feature-packs>
          <layers>
              <layer>cloud-server</layer>
          </layers>
          <runtime-name>ROOT.war</runtime-name>
      </configuration>
      <executions>
          <execution>
              <goals>
                  <goal>package</goal>
              </goals>
          </execution>
      </executions>
    </plugin>
    
mvn install -P openshift
--> ./target/server

./target/server contains WildFly with the Java application deployed in it

Check our server actually works:

./target/server/bin/standalone.sh

curl http://127.0.0.1:9990/health/live
curl http://127.0.0.1:9990/health/ready
  1. create a runnable image

Create a Dockerfile with the following content (see github.com/wildfly/wildfly-s2i/blob/main/ex..)

ARG runtime_image=quay.io/wildfly/wildfly-runtime-jdk11:latest
FROM ${runtime_image}
COPY --chown=jboss:root target/server $JBOSS_HOME
RUN rm -f /opt/server/standalone/configuration/standalone_xml_history/standalone.last.xml /opt/server/standalone/configuration/standalone_xml_history/standalone.boot.xml
RUN chmod -R ug+rwX $JBOSS_HOME

Then create and run the image:

podman build -t myapp:latest .
podman run -p 8081:8080 -p 9990:9990 --rm myapp:latest

curl http://127.0.0.1:9990/health/live
curl http://127.0.0.1:9990/health/ready