Apache Maven is a software project management and comprehension tool.
Based on the concept of a project object model (POM),
Maven can manage a project's build,
reporting and documentation from a central piece of information.
How to use this image
You can run a Maven project by using the Maven Docker image directly,
passing a Maven command to docker run:
This is a base image that you can extend, so it has the bare minimum packages needed. If you add custom package(s) to the Dockerfile, then you can build your local Docker image like this:
docker build --tag my_local_maven:3.8.6-jdk-8 .
Multi-stage Builds
You can build your application with Maven and package it in an image that does not include Maven using multi-stage builds.
# build
FROM maven
WORKDIR /usr/src/app
COPY pom.xml .
RUN mvn -B -e -C -T 1C org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
COPY . .
RUN mvn -B -e -o -T 1C verify
# package without maven
FROM openjdk
COPY --from=0 /usr/src/app/target/*.jar ./
Reusing the Maven local repository
The local Maven repository can be reused across containers by creating a volume and mounting it in /root/.m2.
docker volume create --name maven-repo
docker run -it -v maven-repo:/root/.m2 maven mvn archetype:generate # will download artifacts
docker run -it -v maven-repo:/root/.m2 maven mvn archetype:generate # will reuse downloaded artifacts
Or you can just use your home .m2 cache directory that you share e.g. with your Eclipse/IDEA:
The $MAVEN_CONFIG dir (default to /root/.m2 or C:\Users\ContainerUser\.m2) could be configured as a volume so anything copied there in a Dockerfile
at build time is lost. For that reason the dir /usr/share/maven/ref/ (or C:\ProgramData\Maven\Reference) exists, and anything in that directory will be copied
on container startup to $MAVEN_CONFIG.
To create a pre-packaged repository, create a pom.xml with the dependencies you need and use this in your Dockerfile.
/usr/share/maven/ref/settings-docker.xml (C:\ProgramData\Maven\Reference\settings-docker.xml) is a settings file that
changes the local repository to /usr/share/maven/ref/repository (C:\Programdata\Maven\Reference\repository),
but you can use your own settings file as long as it uses /usr/share/maven/ref/repository (C:\ProgramData\Maven\Reference\repository)
as local repo.
The maven images come in many flavors, each designed for a specific use case.
maven:<version>
This is the defacto image. If you are unsure about what your needs are, you probably want to use this one. It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.
Image Verification
Images under csanchez/maven and ghcr.io/carlossg/maven are signed with sigstore/cosign
using GitHub OIDC
Bats can be easily installed with brew install bats on OS X.
Note that you may first need to:
git submodule init
git submodule update
Pester comes with most modern Windows (Windows 10 and Windows Server 2019), but is an older version than required. You may need to follow this tutorial on upgrading Pester to 4.x.
Adding New Images
Copy an existing dir to the new name and update Dockerfile as needed.
Update README.md to include the new image.
Run github-action-generation.sh to generate new GitHub Actions for the new image
When adding a new JDK then it also needs to be added to the beginning of common.sh
When a parent image changes the latest tag to a new JDK version it can be updated in common.sh
If you have any problems with or questions about this image, please contact us
through a GitHub issue.
You can also reach many of the official image maintainers via the #docker-library IRC channel on Freenode.
Contributing
You are invited to contribute new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.
Before you start to code, we recommend discussing your plans through a GitHub issue,
especially for more ambitious contributions.
This gives other contributors a chance to point you in the right direction,
give you feedback on your design, and help you find out if someone else is working on the same thing.
请发表评论