[JAVA] I made a Docker container to run Maven

Create a Docker Image that can run Apache Maven using Oracle Java published on the Docker Store

Description

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)

Operation image

This is an operation image of building a project with Maven in a Docker container in an environment where Maven is not installed:

Demo

Premise

--You must have a Docker Store account --Check out the Oracle Java 8 Docker image in the Docker Store

Oracle JDK 8

Introduction

Get the image published to Docker Hub

docker pull shinyay/docker-mvn-jdk8:3.5.0

how to use

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]

Docker options

-**-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)

Example 1: 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 clean

Example 2: mvn package

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

Summary

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.

Recommended Posts

I made a Docker container to run Maven
Run React on a Docker container
Run PureScript on a Docker container
I made a bulletin board using Docker 1
How to get a heapdump from a Docker container
I tried running Ansible on a Docker container
I made a Docker image of SDAPS for Japanese
I made a method to ask for Premium Friday
Create a Docker container to convert EPS to PGF source
I made a chat app.
I made a development environment with rails6 + docker + postgreSQL + Materialize.
I made a plugin to execute jextract with Gradle task
[Beginner] I made a program to sell cakes in Java
I tried running a Docker container on AWS IoT Greengrass 2.0
I tried to create a padrino development environment with Docker
[Personal development] I made a site to recruit test users!
I made a Dockerfile to start Glassfish 5 using Oracle Java
Introduction to Linux Container / Docker (Part 1)
Ruby: I made a FizzBuzz program!
Steps to run docker on Mac
I made a shopify app @java
I made a GUI with Swing
How to run JavaFX on Docker
Run GUI application on Docker container
Introduction to Linux Container / Docker (Part 2)
I made a simple recommendation function.
How to make a Maven project
Pass environment variables to docker container
[Docker] Operation up to container creation # 2
I made a matching app (Android app)
I made a package.xml generation tool.
[Android] I made a pedometer app.
I created a Docker image of a container for learning OpenAI Gym
I made a Ruby container image and moved the Lambda function
I tried to integrate Docker and Maven / Netbean nicely using Jib
A little happy that Nginx's Docker container defaults to graceful shutdown
I made a gem to post the text of org-mode to qiita
How to run a job with docker login in AWS batch
I made a method to ask for Premium Friday (Java 8 version)
I tried deploying a Docker container on Lambda with Serverless Framework
I made a tool to output the difference of CSV file
I tried to build a laravel operating environment while remembering Docker
I can no longer connect to a VM with a Docker container that can be connected via SSH
I was angry with proc_open (): fork failed when trying to composer update inside a Docker container
I want to develop a web application!
Docker push to GitHub Container Registry (ghcr.io)
I want to write a nice build.gradle
[Ruby] I made a simple Ping client
Run NordVPN on Docker (Windows) Ubuntu container
Run Embulk on Docker to convert files
I made an app to scribble with PencilKit on a PDF file
I want to write a unit test!
How to create a Maven repository for 2020
I tried to build a Firebase application development environment with Docker in 2020
I made a virtual currency arbitrage bot and tried to make money
Run x11 apps in a Docker container (supports network access from the container)
I made a risky die with Ruby
[Docker] Copy files from docker container to host
Quick build maven project using maven docker container
I made a plugin for IntelliJ IDEA
I made a rock-paper-scissors app with kotlin