This project uses Google Jib to build optimised Docker/OCI images, without the need for a Dockerfile and Docker Engine.
The Maven plugin supports the definition of the container in pom.xml
and provides new goals to build a container. The full documentation for the Maven Plugin can be found here.
Jib supports building container images for multiple platform architectures e.g. linux/amd64
, linux/arm64
.
Note: in order to achieve this the base image must support the desired platforms.
The Amazon Corretto OpenJDK 11 base image supports both linux/amd64
and linux/arm64
.
Jib supports build and pushing of images to a cloud container registry including:
- DockerHub
- Google Container Registry (GCR)
- AWS Elastic Container Registry (ECR)
- Azure Container Registry (ACR)
- JFrog Container Registry (JCR)
The following command can be used to build and push images to a registry.
mvn compile jib:build
The configuration of the destination registry and authentication methods are documented here:
The following steps describe how to build to a local registry
- Launch a local docker registry
docker run -d -p 5001:5000 --name registry registry:2
- Set
docker.registry
property in pom.xml
<docker.registry>localhost:5001/</docker.registry>
- Set
docker.allowInsecureRegistries
property inpom.xml
<docker.allowInsecureRegistries>true<docker.allowInsecureRegistries>
- Run the build
mvn compile jib:build
Jib supports building an image directly to a local docker daemon. However it is not possible to build for multiple platforms with this approach.
In order to build an image for a specific platform (either linux/amd64 or linux/arm64) two maven profiles have been configured:
mvn compile jib:dockerBuild -P docker-amd64
mvn compile jib:dockerBuild -P docker-arm64