Running WAR apps in Docker with Jib

In the past I have written an article regarding Launching your Vaadin apps in Docker. That required you to write the Dockerfile. However there is even simpler way: Jib.

We’re going to launch the Karibu HelloWorld App in Docker. First, clone the repo:

$ git clone https://github.com/mvysny/karibu-helloworld-application

Then, edit the build.gradle.kts file and add the Jib plugin:

plugins {
   // ...
   id("com.google.cloud.tools.jib") version "1.7.0"
}

Jib will automatically detect that the project is a WAR project and will use Jetty Docker image (you can read more about this at Jib War Projects). However, to force a specific Jetty image just add this to build.gradle.kts:

jib {
    from {
        image = "jetty:9.4.18-jre11"
    }
    container {
        appRoot = "/var/lib/jetty/webapps/ROOT"
    }
}

To build the Docker image locally, simply run

$ ./gradlew clean build jibDockerBuild --image=test/karibu-helloworld-app

To run the image:

$ docker run --rm -ti -p8080:8080 test/karibu-helloworld-app

Done - your app is now running at localhost:8080.

Written on March 29, 2019