The first step after creating the Vaadin app in the last post Hello Vaadin was to create a Docker image for it.

Since there is a good Gradle plugin for managing Docker available, it wasn’t much work to create the image.

As a base image I decided on the official Jetty image and built the image by adding the WAR file of my application to it.

My build.gradle from the last post grew a little to

buildscript {
 repositories {
  jcenter()
 }

 dependencies {
  // https://github.com/bmuschko/gradle-docker-plugin
  classpath 'com.bmuschko:gradle-docker-plugin:3.0.6'
 }
}

plugins {
 id "fi.jasoft.plugin.vaadin" version "1.1.10"
}

apply plugin: 'com.bmuschko.docker-java-application'
apply plugin: 'com.bmuschko.docker-remote-api'

import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage

task createDockerfile(type: Dockerfile) {
 destFile = project.file('./build/Dockerfile')
 from 'jetty:9'
 maintainer 'The Dude <thedude@email.com>'
 addFile "./libs/hello-vaadin.war", "/var/lib/jetty/webapps/"
}

task buildImage(type: DockerBuildImage) {
 inputDir = createDockerfile.destFile.parentFile
 tag = 'thedude/hello-vaadin:1.0'
}

task pushImage(type: DockerPushImage) {
 imageName = "thedude/hello-vaadin"
 tag = '1.0'
}

createDockerfile.dependsOn war
buildImage.dependsOn createDockerfile
pushImage.dependsOn buildImage

Two steps remain: building the image and running the corresponding container.

Building the image is simply gradle buildImage and running it with

docker run -ti -p 8888:8080 thedude/hello-vaadin:1.0

Then check in the browser at http://localhost:8888/hello-vaadin/.

If everything looks good, push the image with gradle pushImage.

Done for today!