2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018

04/20/2015: Running Maven inside Docker.

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!



subscribe via RSS