How to install Nexus on Docker


Nexus Repository is a repository manager developed by Sonatype. It is used to store, retrieve, and manage software packages (binaries) and dependencies in various formats, such as Maven, npm, Docker, and more.

For us, Mulesoft Architects and Developers, it’s an important element as in many organizations the compiled and tested mule artifacts are stored in Nexus.

Nexus Repository helps organizations manage mulesoft artifacts efficiently, secure their supply chain, and optimize development workflows.
There are two versions of Nexus Repository:
  • Nexus Repository OSS: The open-source version with core features.
  • Nexus Repository Pro: The paid version with additional features like advanced security, clustering, and high availability.
In this post, we will see how to install Nexus on a Docker container. Although, this is something we would install in a production environment, a docker container is a very useful alternative for testing purposes.

For the installation on Docker we will follow the next steps:

Download the Nexus image

The first thing is to download the Nexus image to our local Docker host. The official image can be found at https://hub.docker.com/r/sonatype/nexus3/. To download the image run the command:
docker pull sonatype/nexus3

Create a Docker Volume

Create a docker volume for the Nexus data. This data is used by Nexus for configuration, logs and storage. This directory needs to be writable by the Nexus process, which runs as UID 200.
docker volume create --name nexus-data


Run the Container

Run the command
docker run -d --name [NEXUS_CONTAINER_NAME] -p 8081:8081 -v nexus-data:/nexus-data sonatype/nexus3
Where:
  • -d: run in dettachable mode
  • --name [nexus_container_name]: Provides a name for the container
  • -p 8081:8081: Maps the port 8081 in the host to port 8081 in the container. Port 8081 is used for the web access console
  • -v nexus-data:/nexus-data: maps the /nexus-data directory in the container to the nexus-data volume we’ve created

Finish the Installation

The installation might take 2-3 minutes. We can tail the log of the container to see how the installation is proceeding with the command
    docker logs -f [NEXUS_CONTAINER_NAME]


Test the installation

Open your browser and go to http://localhost:8081



Alternatively we can test with the curl command
$ curl http://localhost:8081/


Log in as Admin

The admin password is located in the /nexus-data/admin.password file in the container. The default admin user name is admin. To get the admin password run the command
docker container exec [NEXUS_CONTAINER_NAME] cat /nexus-data/admin.password


If you’re using Docker on macOS you can access the password file from the Volumes section.


Once you get the password, click on Sign in and provide the copied admin password. You will then be prompted to create a new password. You will also need to decide if you allow anonymous access to your Nexus instance or not.


With that, your new Nexus repository is ready to get your Mule apps!
Previous Post Next Post