Featured image of post Introduction to Installing and Deploying Nexus with Docker and Direct Methods

Introduction to Installing and Deploying Nexus with Docker and Direct Methods

Nexus Introduction: Nexus is a Maven repository manager that can be used to store, distribute, and manage software packages and libraries. It is developed by Sonatype and comes in both community and professional versions.

Introduction to Nexus

Nexus is a Maven repository manager used for storing, distributing, and managing software packages and libraries. Developed by Sonatype, it is an open-source project that offers both community and professional editions.

Nexus supports various types of Maven repositories, including Maven2, Maven3, npm, and Docker, and provides a range of features such as security, license management, user management, and customizable workflows. With Nexus, users can manage and distribute software more efficiently while saving storage space and bandwidth.

The main features of Nexus include:

  1. Unified Repository Management: Nexus allows you to manage multiple repositories through a single interface, organizing them into logical repositories.
  2. Security Policies: You can enforce strict access control on repositories and groups, allowing only authorized users to access certain content.
  3. Hosting Libraries: Nexus can host your packages, dependencies, and other binaries, providing secure HTTPS upload and download options.
  4. Automation: You can automate processes such as publishing to the Maven Central Repository, auditing, and version control, enhancing release efficiency and quality.

In summary, Nexus is a powerful Maven repository manager that helps users manage and distribute software packages and libraries while improving software release quality and efficiency.

Here are a few methods for installing and deploying Nexus:

Installing and Deploying Using Docker Image

Docker Image Download Link: Nexus Docker Hub. The Docker image is only available for version 3.x; if you need version 2.x, please refer to the system installation methods below.

To install Nexus in Docker, follow these steps:

  1. Pull the Nexus Docker Image

    Execute the following command to pull the Nexus Docker image:

    1
    
    docker pull sonatype/nexus3
    
  2. Create and Start the Nexus Container

    Use the following command to create and start the Nexus container:

    1
    
    docker run -d -p 8081:8081 --name nexus sonatype/nexus3
    

    This command creates and starts a container named nexus, mapping the Nexus service in the container to port 8081 on the host.

  3. Access the Nexus Web Interface

    Enter http://<host>:8081 in your browser, where <host> is the IP or domain name of the Docker host. Upon your first visit, you will be prompted to set up the username and password for the admin account. Once set, you can access the Nexus Web interface.

  4. Configure Nexus

    In the Nexus Web interface, you can perform various configurations, such as creating Maven repositories, uploading and downloading software packages, etc. For specific procedures, please refer to the official Nexus documentation.

  5. Data Persistence

    By default, data for Docker containers is stored internally, and this data will be lost when the container is deleted or recreated. To preserve data in Nexus, you need to mount the data directory to the host.

    You can create a data volume with the following command and then mount it to the /nexus-data directory in the Nexus container:

    1
    
    mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
    
    1
    
    docker run -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3
    

    This will create a data volume named nexus-data and mount it to the /nexus-data directory in the Nexus container, ensuring that data is retained even when the Nexus container is deleted or recreated.

Introduction to Installing and Deploying Nexus with Docker

Viewing Logs

To view the logs:

1
docker logs -f nexus

Output (indicating successful startup):

1
2
3
4
5
6
|  | ------------------------------------------------- |
| --- | --- |
|  |  |
|  | Started Sonatype Nexus OSS 3.37.3-02 |
|  |  |
|  | ------------------------------------------------- |

Viewing the Password

To view the admin password:

1
docker exec -it nexus more /nexus-data/admin.password

Accessing the Container

To enter into the container:

1
docker exec -it nexus bash

Stopping the Container

Make sure to stop the database gracefully, allowing for additional closing time:

1
docker stop --time=120 nexus

In summary, installing Nexus using Docker involves pulling the Nexus image, creating and starting the Nexus container, accessing the Nexus Web interface, configuring Nexus, and ensuring data persistence.

Direct Installation on Linux Systems

  1. Download Nexus

    Download the latest version of Nexus from the official website: Nexus Downloads.

    Choose the appropriate archive for your system. If you are using Linux, you can download it using the following command:

    1
    
    wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
    
  2. Extract Nexus

    Unpack the downloaded Nexus archive to the desired installation directory. If you are on Linux, you can use the following command:

    1
    
    tar -zxvf latest-unix.tar.gz
    
  3. Configure Nexus

    Navigate to the extracted Nexus directory and edit the bin/nexus.rc file.

    Modify the following parameters in the file:

    • run_as_user: Specify the user that runs Nexus; the default is root.
    • nexus_home: Specify the installation path for Nexus.
  4. Start Nexus

    Execute the following command to start Nexus:

    1
    
    ./bin/nexus start
    

    This command will start Nexus and run it as a background process. You can stop Nexus using the following command:

    1
    
    ./bin/nexus stop
    
  5. Access Nexus

    Enter http://<nexus_host>:8081 in your browser, where <nexus_host> is the IP or domain name of the Nexus host.

    Upon your first visit, you will be prompted to set up the username and password for the admin account. Once done, you can access the Nexus management console.

In conclusion, installing Nexus involves downloading the archive, extracting it to a specified directory, editing the nexus.rc configuration file, and then starting Nexus from the command line. Once installed, you can access the Nexus management console through your browser for configuration and use.

For information on backing up and restoring Nexus, please refer to this link: Backup and Restore Nexus