You will create a container for a Vert.x app packaged as an executable uber-jar.
The how-to consists in a couple of files:
- 
the docker-maven/Dockerfile, for Maven users, or
- 
the docker-gradle/Dockerfile, for Gradle users.
First, generate the project from https://start.vertx.io:
- 
Select the Mavenbuild type
- 
Set the artifactIdtocontainer-uber-jar
- 
Select the JDK 11JDK version
- 
Click on generate and extract the content somewhere on your disk 
Alternatively, open a terminal and run:
curl -G https://start.vertx.io/starter.zip -d "artifactId=container-uber-jar" -d "jdkVersion=11" -d "buildTool=maven" --output container-uber-jar.zip
unzip container-uber-jar.zipOr, with HTTPie:
http https://start.vertx.io/starter.zip artifactId==container-uber-jar jdkVersion==11 buildTool==maven --output container-uber-jar.zip
unzip container-uber-jar.zipAt the root of the project, create a docker-maven/Dockerfile build file:
The Docker build has two stages:
- 
Building the Maven project inside a maven:3.9.9-eclipse-temurin-11container
- 
Copying the output of the build in a eclipse-temurin:11container and configuring the entry point
The benefits of this approach are:
- 
reproducible build: no matter who in the team runs the Docker build, it will always use the same Maven version and JDK version (both at build-time and run-time) 
- 
small container image size: the final container will be based on a slim JDK image and will only add the uber-jar file 
To build the container, open a terminal at the root of the project and run:
docker build -t com.example/container-uber-jar -f docker-maven/Dockerfile .First, generate the project from https://start.vertx.io:
- 
Select the Gradlebuild type
- 
Set the artifactIdtocontainer-uber-jar
- 
Select the JDK 11JDK version
- 
Click on generate and extract the content somewhere on your disk 
Alternatively, open a terminal and run:
curl -G https://start.vertx.io/starter.zip -d "artifactId=container-uber-jar" -d "jdkVersion=11" -d "buildTool=gradle" --output container-uber-jar.zip
unzip container-uber-jar.zipOr, with HTTPie:
http https://start.vertx.io/starter.zip artifactId==container-uber-jar jdkVersion==11 buildTool==gradle --output container-uber-jar.zip
unzip container-uber-jar.zipAt the root of the project, create a docker-gradle/Dockerfile build file:
The Docker build has two stages:
- 
Building the Gradle project inside a gradle:8.1.1-jdk11container
- 
Copying the output of the build in a eclipse-temurin:11container and configuring the entry point
The benefits of this approach are:
- 
reproducible build: no matter who in the team runs the Docker build, it will always use the same Gradle version and JDK version (both at build-time and run-time) 
- 
small container image size: the final container will be based on a slim JDK image and will only add the uber-jar file 
To build the container, open a terminal at the root of the project and run:
docker build -t com.example/container-uber-jar -f docker-gradle/Dockerfile .Now that you have built the container image, it is time to try it out!
Open a terminal and run:
docker run -p 8888:8888 com.example/container-uber-jarYou should see messages like these on the console output:
HTTP server started on port 8888 Dec 02, 2024 5:17:19 PM io.vertx.launcher.application.VertxApplication INFO: Succeeded in deploying verticle
Then browse to http://localhost:8888 and get your greeting from the Vert.x app running in the container!
This document covered:
- 
configuring a Docker build for Maven users, 
- 
configuring a Docker build for Gradle users.