https://github.com/vertx-howtos/executable-jar-docker-howto
Creating a container for a Vert.x app packaged as an executable uber-jar
https://github.com/vertx-howtos/executable-jar-docker-howto
docker executable-jar howto vertx
Last synced: 12 days ago
JSON representation
Creating a container for a Vert.x app packaged as an executable uber-jar
- Host: GitHub
- URL: https://github.com/vertx-howtos/executable-jar-docker-howto
- Owner: vertx-howtos
- License: apache-2.0
- Created: 2021-03-15T17:51:57.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-02T17:19:13.000Z (5 months ago)
- Last Synced: 2025-03-23T21:22:31.590Z (29 days ago)
- Topics: docker, executable-jar, howto, vertx
- Language: Java
- Homepage:
- Size: 326 KB
- Stars: 0
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Creating a container for a Vert.x app packaged as an executable uber-jar
:page-permalink: /
:page-github: vertx-howtos/executable-jar-docker-howtoifdef::env-github[]
image:https://github.com/vertx-howtos/executable-jar-docker-howto/actions/workflows/publish.yml/badge.svg["Publish the how-to", link="https://github.com/vertx-howtos/executable-jar-docker-howto/actions/workflows/publish.yml"]
endif::env-github[]== What you will create
You will create a container for a Vert.x app packaged as an executable https://stackoverflow.com/a/11947093/2133695[_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.== What you need
* A text editor or IDE
* Docker== Using Maven
=== Generate the project
First, generate the project from https://start.vertx.io:
. Select the `Maven` build type
. Set the `artifactId` to `container-uber-jar`
. Select the `JDK 11` JDK version
. Click on generate and extract the content somewhere on your diskAlternatively, open a terminal and run:
[source,bash]
----
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.zip
----Or, with HTTPie:
[source,bash]
----
http https://start.vertx.io/starter.zip artifactId==container-uber-jar jdkVersion==11 buildTool==maven --output container-uber-jar.zip
unzip container-uber-jar.zip
----=== Configuring the Docker build
At the root of the project, create a `docker-maven/Dockerfile` build file:
ifdef::env-github[]
link:docker-maven/Dockerfile[Docker build file for a Maven project]
endif::env-github[]
ifndef::env-github[]
[source,dockerfile]
.Docker build file for a Maven project
----
include::docker-maven/Dockerfile[]
----
endif::env-github[]The Docker build has two stages:
. Building the Maven project inside a `maven:3.9.9-eclipse-temurin-11` container
. Copying the output of the build in a `eclipse-temurin:11` container and configuring the entry pointThe 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 fileTo build the container, open a terminal at the root of the project and run:
[source,bash]
----
docker build -t com.example/container-uber-jar -f docker-maven/Dockerfile .
----== Using Gradle
=== Generate the project
First, generate the project from https://start.vertx.io:
. Select the `Gradle` build type
. Set the `artifactId` to `container-uber-jar`
. Select the `JDK 11` JDK version
. Click on generate and extract the content somewhere on your diskAlternatively, open a terminal and run:
[source,bash]
----
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.zip
----Or, with HTTPie:
[source,bash]
----
http https://start.vertx.io/starter.zip artifactId==container-uber-jar jdkVersion==11 buildTool==gradle --output container-uber-jar.zip
unzip container-uber-jar.zip
----=== Configuring the Docker build
At the root of the project, create a `docker-gradle/Dockerfile` build file:
ifdef::env-github[]
link:docker-gradle/Dockerfile[Docker build file for a Gradle project]
endif::env-github[]
ifndef::env-github[]
[source,dockerfile]
.Docker build file for a Gradle project
----
include::docker-gradle/Dockerfile[]
----
endif::env-github[]The Docker build has two stages:
. Building the Gradle project inside a `gradle:8.1.1-jdk11` container
. Copying the output of the build in a `eclipse-temurin:11` container and configuring the entry pointThe 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 fileTo build the container, open a terminal at the root of the project and run:
[source,bash]
----
docker build -t com.example/container-uber-jar -f docker-gradle/Dockerfile .
----== Running the application
Now that you have built the container image, it is time to try it out!
Open a terminal and run:
[source,bash]
----
docker run -p 8888:8888 com.example/container-uber-jar
----You 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!
== Summary
This document covered:
. configuring a Docker build for Maven users,
. configuring a Docker build for Gradle users.== See also
- https://docs.docker.com/engine/reference/builder/[Dockerfile reference]
- https://docs.docker.com/develop/develop-images/multistage-build/[Multi-stage builds introduction]