How to Publish Docker Images on Private Nexus Repository Using Jib Maven Plugin
In this article, see how to publish Docker images on a private Nexus repository using Jib Maven plugin.
Join the DZone community and get the full member experience.Join For Free
Docker is a lightweight container used for publishing apps with an entire ecosystem packaged in single bundle.
Jib is a framework that builds and compiles Docker images with and without Docker daemon available on the system. There are two plugins available for this one, for Maven, and for Gradle. In this exercise, we are going to use a jib maven plugin to publish a Docker image.
Nexus is a repository manager tool used for hosting various types of artifacts like jar, npm packages, and Docker/OCI images.
There are some prerequisites for this tutorial to be completed.
1. Download Nexus from below location; you need to choose your operating system version
2. Extract it to a location call it install_location for example D:\nexus
3. Start Nexus by running command as administrator
3.1 If step three fails due to port conflict, there will be file created by nexus start called nexus.properties at
You need to change the port to any port non-conflicting port 9081, note this file will be created only when nexus starts up successfully
4. Login to nexus as admin
Your password is in admin.password file that gets created after nexus start-up
4.1 You need to find the default password for admin you can find this at below location
Once you login to the system, click on the "go to repositories" tab from the left menu and click the "create repository" button shown below:
In the second screen, please select Docker hosted as a recipe type by double-clicking it.
Now enter registry name and http port and the rest of the things as default and click on the create repository button at the bottom part of the screen. This http port is used in pom.xml for publishing
Now go to https://start.spring.io/ and download a basic Spring Boot app with Maven as a build tool.
You also need to have Maven configured in your class path or use mvnw command.
Now open spring initializer project in the editor of your choice. I used visual studio code, but you can use any.
We need to add the below things to pom.xml of the project. Jib plugin and right entries for Docker registry that we created in the prerequisite section. The config part is very important, as this step will make or break this exercise.
Find the plugins section under pom.xml and add the below entry to the pom.xml. Note you need to change the password to the same as what you created when setting up nexus.
Save the file and run the below command from command line under the directory where you extracted the Spring Boot application.
mvn compile jib:build -DsendCredentialsOverHttp=true -Djib.httpTimeout=0
The above command will build your first Docker image without installing Docker daemon on the machine and push it to the nexus repo. Flag httpTimeout is worth mentioning as the default value for this in 2 seconds usually repos take longer than this, hence I kept it at infinite. Flag SendCredentialsOverHttp is used for allowing http and authentication needs as Jib uses https and credshelper. The idea is to get things started and see things end to end.
Opinions expressed by DZone contributors are their own.