Maven plugin for docker: embedding a Spring Boot application

We will take an example of how to use a Maven plugin for docker to embed a Spring Boot application. The Maven plugin that I am using is:

https://github.com/spotify/dockerfile-maven

These are the basic operations that I do with this plugin:

  1. Given a Dockerfile, I create a docker image by saying mvn dockerfile:build. This builds the docker image from the jar file in my target folder
  2. After building the docker file, I would like to push it to my docker hub repository by using the command mvn dockerfile:push.

This is how I define the docker plugin in my pom.xml:

Note that I have defined my docker repository details in the repository tag.

This is how the Dockerfile looks like:

Providing encrypted credentials to Maven

In addition to the above, I also need to provide my credentials for docker.io. And, of course, the password should be encrypted. Maven supports encryption. I have largely followed the below link:

https://maven.apache.org/guides/mini/guide-encryption.html

Step 1: Create a master password

Create a master password by typing:

Say, it gives you the below output:

{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}

Create a file: ~/.m2/settings-security.xml with the following content:

Step 2: Create an encrypted password

Create the encrypted password for your docker.io user. Type:

Say, the output is:

{COQLCE6DU6GtcS5P=}

In the ~/.m2/settings.xml file, add the below lines under the servers tag.

Now, you should be all set. Use the below command to build the docker image and then push it:

Sources

A working example of this can be found here:

https://github.com/paawak/blog/tree/master/code/spring-boot-demo

Leave a Reply

Your email address will not be published. Required fields are marked *