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. Because of Issue 591 we need to add the following on the top of the build.gradle.kts file:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("com.google.guava:guava:27.0.1-jre")
    }
}

Then, just add the Jib plugin:

plugins {
   ...
   id("com.google.cloud.tools.jib") version "1.3.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).

To build the Docker image locally, simply run

$ ./gradlew 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