Create a Docker Image that can run Apache Maven using Oracle Java published on the Docker Store
Apache Maven is a well-known tool for project management (build and configuration management) of Java projects. In order to use this Maven, it is usually necessary to install Java, install Maven, pass the path, and set JAVA_HOME and MAVEN_HOME. I prepared such a series of environment as a Docker image in advance. By using this, you will be able to build Maven projects very much without Maven installed.
The Maven environment prepared here uses Java 8 provided by Oracle published on the Docker Store as the Java runtime. I will.
Below is the Java and Maven version information.
--Java: Oracle JDK 8 (1.8.0_131: latest image version as of July 2017)
This is an operation image of building a project with Maven in a Docker container in an environment where Maven is not installed:
--You must have a Docker Store account --Check out the Oracle Java 8 Docker image in the Docker Store
Get the image published to Docker Hub
docker pull shinyay/docker-mvn-jdk8:3.5.0
Mount the Maven project in your host environment into a Docker container, move your working directory to the mount point, and run the Maven command.
docker run -it --rm -v [Maven project path in host environment]: [mount point in container environment] -w [mount point in container environment] shinyay / docker-mvn-jdk8: 3.5.0 mvn [ MAVEN GOAL]
-**-it : Secure standard input / tty terminal device --rm : Destroy the container when it exits --v : Volume mount --w **: Specify working directory (default is root directory)
docker run -it --rm -v /home/shinyay/works/mvn-projects/mvn-webapp/mytest-app:/usr/src/mvnproject -w /usr/src/mvnproject shinya/mvn:3.5.0 mvn clean
docker run -it --rm -v /home/shinyay/works/mvn-projects/mvn-webapp/mytest-app:/usr/src/mvnproject -w /usr/src/mvnproject shinya/mvn:3.5.0 mvn package
This is useful when using a virtual image that does not include Maven.
The future improvement is that the repository after running Maven is not cached, so when you try to run it again, the dependent libraries will be reacquired. However, it would be nice to share it with the Maven repository in the host environment.