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:
This is how I define the docker plugin in my pom.xml:
com.spotify dockerfile-maven-plugin default build push docker.io/paawak/spring-boot-demo ${project.version}
Note that I have defined my docker repository details in the repository tag.
This is how the Dockerfile looks like:
FROM java:8 MAINTAINER Palash RayADD target/spring-boot-demo-0.0.1-SNAPSHOT.jar // ENTRYPOINT ["java", "-jar", "/spring-boot-demo-0.0.1-SNAPSHOT.jar"]
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
Create a master password by typing:
mvn --encrypt-master-password
Say, it gives you the below output:
{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}
Create a file: ~/.m2/settings-security.xml with the following content:
{jSMOWnoPFgsHVpMvz5VrIt5kRbzGpI8u+9EF1iFQyJQ=}
Create the encrypted password for your docker.io user. Type:
mvn --encrypt-password
Say, the output is:
{COQLCE6DU6GtcS5P=}
In the ~/.m2/settings.xml file, add the below lines under the servers tag.
docker.io paawak {COQLCE6DU6GtcS5P=}
Now, you should be all set. Use the below command to build the docker image and then push it:
mvn clean install dockerfile:build dockerfile:push
A working example of this can be found here:
https://github.com/paawak/blog/tree/master/code/spring-boot-demo