Let’s create a Vert.x docker image of our application

As you’ve probably realised from previous posts, I’m very much into the idea of deploying my server applications via Docker, so let’s take the VertxTest application and create a Docker image with it.

Thankfully we do not need to start our Dockerfile by creating a base OS then adding Java etc. The people writing Vert.x have kindly implemented a base image for us.

See Deploying a Java verticle in a docker container.

If we take the example Dockerfile from their website and make the changes for our application (just replace VERTICAL_NAME and VERTICLE_FILE with our main verticle and the JAR) we get the following file

FROM vertx/vertx3

ENV VERTICLE_NAME com.putridparrot.MainVerticle
ENV VERTICLE_FILE VertxTest-1.0-SNAPSHOT-fat.jar

ENV VERTICLE_HOME .

EXPOSE 8080

COPY $VERTICLE_FILE $VERTICLE_HOME/

WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["exec vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]

Place this Dockerfile into a folder along with the compiled JAR and then execute

docker build -t vertx_test  .

This creates an image name vertx_test which we can now execute. If you want to watch the output from our System.out.println execute

docker run -it -p 8080:8080 vertx_test

Once you see the HTTP server started on port 8080 outputs, the Vert.x application will be ready for you to access via your preferred web browser etc.