I recently reinstalled Ubuntu on my zareason laptop. As I was thinking about installing my development tools, I thought about how to integrate Docker into the process. Below I show how simple using the Maven container can be:

* Create an alias to the Maven container.

alias mvn="docker run \
  -it \
  --rm \
  --name my-maven-project \
  -v "$PWD":/usr/src/mymaven \
  -w /usr/src/mymaven \
  maven:3.3-jdk-8 \
  mvn"

* Clone my ragnvald Java project.

git clone git@github.com:medined/ragnvald.git

* cd ragnvald

* Package  the project.

mvn package
 That's it. You're using Maven without installing onto your laptop! The results of the compilation are placed into the target directory.

If you need to specify a Maven settings.xml file that's fairly easy as well. Simply create it alongside the pom.xml file. Then slightly modify your alias:

alias mvn="docker run \
  -it \
  --rm \
  --name my-maven-project \
   -v "$PWD":/root/.m2 \
   -v "$PWD":/usr/src/mymaven \
   -w /usr/src/mymaven \
  maven:3.3-jdk-8 \
  mvn"

The ragnvald project goes one step farther to use an Artifactory container so that I can use the Artifactory web interface if needed. That's quite convenient!