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' services: nexus-data: image: sonatype/nexus3 entrypoint: - /bin/true nexus: image: sonatype/nexus3 volumes_from: - nexus-data depends_on: - nexus-data ports: - "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
<mirror>
This sends everything else to /public
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
You also need to add the tag to your <profile> section
<id> nexus </id>
<activeProfile>nexus</activeProfile>
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.
Nice Article. In short description good explanation about the DevOps. Thanks For sharing the informative news.