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 "3.0.0"
}

Note: these instructions might be outdated. Please see the vaadin-kotlin-pwa build.gradle.kts file for the most up-to-date JIB plugin configuration.

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.40-jre11"
    }
    container {
        appRoot = "/var/lib/jetty/webapps/ROOT"
        user = "root" // otherwise we'll get https://github.com/appropriate/docker-jetty/issues/80
    }
}

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