We often require a maven repository to show some of our product features. There is a quick and dirty way to have a maven repository running in no time.

You can use the docker-compose file from this blog’s GitHub repository here. Here is the content if you are feeling bored or lazy to open GitHub

version: '2'
 image: sonatype/nexus3
 - /bin/true
 image: sonatype/nexus3
 - nexus-data
 - nexus-data
 - "8081:8081"

This will first download the image from Docker hub and then starts two containers one is the Nexus Repository software and the other is a data container for persistence. Using a data container ensures that if you stop your containers and start them again, your artifacts are not lost.

Start the nexus repository by running the following command where the docker-compose file is located.

docker-compose up

If everything goes well, you should see the following in your console

nexus_1 | -------------------------------------------------
nexus_1 |
nexus_1 | Started Sonatype Nexus OSS 3.1.0-04
nexus_1 |
nexus_1 | -------------------------------------------------

You can open up your browser and enter http://localhost:8081 to access the repository. You should be greeted with this page


That’s it. You now have a maven repository to push your artifacts to. We’ll later use this repository for other posts. In order to use this with your local maven installation, you will need to udpate your settings.xml file in ~/.m2/ folder (sorry Windows users you’ll need to find the .m2 folder) with the entry of your repository. In the tag you will need to add the following

This sends everything else to /public

You also need to add the tag to your <profile> section

<id> nexus </id>

Lastly you need to make the nexus profile the active profile by adding it to your <activeProfiles> section
A sample settings.xml is also in my Github repo for you to use if you have a vanilla Maven installation.

If you want to dump your containers and start fresh, you can just run

docker-compose down

Re-running docker-compose up will give you a fresh install.

Need even more information, head over to the GitHub page of Sonatype Nexus.