Home Sonatype Nexus Repository OSS
Post
Cancel

Sonatype Nexus Repository OSS

1-nexus

About Sonatype Nexus Repository OSS

What is Sonatype Nexus Repository OSS

Sonatype Nexus Repository - Smart repository to manage and build artifacts, trusted by more than 150K orgranizations. Nexus OSS, also known as Nexus Open Source Software, is a repository manager used for storing and managing artifacts such as libraries, dependencies, and Docker images. It ensures that artifacts are available and accessible to all members of your development team.

Nexus Repository Supports Formats

Nexus Repository supports the repository formats listed below.

FormatDescription
APTUse Advanced Package Tool (APT) tools such as apt-get to access hosted Debian, Ubuntu and other Linux software packages.
BowerKeep track of all your web site frontend development packages using Bower registries. Note that Bower format is not compatible with H2 or PostgreSQL databases.
CocoaPodsManager for CocoaPods packages (which might contain Swift code) and Objective-C Cocoa projects. Note that we do not support Apple’s Swift package manager.
ConanShare your C/C++ packages in a central repository.
CondaProxy Conda packages for languages such as Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++ and FORTRAN.
DockerProxy popular Docker registries such as DockerHub and host your own private images securely.
Git LFSStore large files such as audio samples, videos, datasets, and graphics inside repositories and use simple text pointers to these inside your Git project.
GoModernize your development process and store Go (golang) dependencies for fast, repeatable local builds.
HelmManage packages for Kubernetes by accessing Helm Charts in Helm repositories.
MavenLeverage the most experienced Maven repository format product to host your private Java components and proxy defacto public repositories like Central using tooling such as Maven, Ant and Gradle.
npmPublish your javascript node.js projects to hosted registries and integrate dependencies from external JavaScript package registries.
NuGetUse NuGet client compatible tooling to push and install .Net packages. Development is easier using consolidated hosted and proxy registries.
p2Proxy p2 format repositories for your Eclipse IDE and other Equinox based application dependencies.
PyPIPython development tools such as pip and twine can be used install and publish packages to PyPI repositories.
RProxy packages from the official R registry and host your own packages.
RawA flexible format that does not enforce any type of layout enabling you to store and serve any type of binary content such as Maven sites over HTTP.
RubyGemsHost your own gems and proxy remote gem repositories like rubygems.org.
YumFirst class support for hosting and proxying your RPM distributions.

Set Up Environment

Checkout jasonlws/sontype-nexus GitHub repository

Clone jasonlws/sontype-nexus repository

1
$ git clone https://github.com/jasonlws/sontype-nexus.git

Docker

Created a customized Docker image jasonlws/nexus3 which based on the official Nexus Repository Docker image from Sonatype, but

  • Added a default password P@ssw0rd, so you don’t need retrieve from admin.password file.

Running

To run, building the exposed port 8081 to the host, use

1
$ docker run --name jasonlws-nexus3 -p 8081:8081 -v /some/dir/nexus-data:/nexus-data -d jasonlws/nexus3:3.70.1-java8-ubi

Presistent Data

Docker Volume

Use a docker volume. Since docker volumes are persistent, a volume can be created specifically for this purpose. This is the recommended approach.

1
2
$ docker volume create nexus-data
$ docker run --name jasonlws-nexus3 -p 8081:8081 -v nexus-data:/nexus-data -d jasonlws/nexus3:3.70.1-java8-ubi
Mount a Host directory

Mount a host directory as the volume. This is not portable, as it relies on the directory existing with correct permissions on the host. However it can be useful in certain situations where this volume needs to be assigned to certain specific underlying storage.

Linux
1
$ docker run --name jasonlws-nexus3 -p 8081:8081 -v /docker-compose/nexus-data:/nexus-data -d jasonlws/nexus3:3.70.1-java8-ubi
Windows
1
$ docker run --name jasonlws-nexus3 -p 8081:8081 -v ${PWD}//docker-compose//nexus-data//:/nexus-data -d jasonlws/nexus3:3.70.1-java8-ubi

Vagrant

Install a Box

This will download the box named generic/ubuntu2004 from HashiCorp’s Vagrant Cloud box catalog, where you can find and host boxes.

1
$ vagrant box add generic/ubuntu2004

Bring up a virtual machine

Go to Vagrant folder and run the following from your terminal:

1
$ vagrant up

Destroy a virtual machine

Go to Vagrant folder and run the following from your terminal:

1
$ vagrant destroy jasonlws-nexus -f

Configuration

Open http://127.0.0.1:8081 to access Sonatype Nexus Repository OSS user interface.

First Login

To ensure the system begins with a secure state, Nexus Repository Manager generates a unique random password during the system’s initial startup which it writes to the data directory ($data-dir, typically sonatype-work/nexus3) in a file called admin.password. However, I just change it to a default password P@ssw0rd for easy use.

Click the Sign in button in the top right of the page. When using the user interface another step in the wizard is configuring whether anonymous access is allowed in the system. Until configured the system will allow unauthenticated users to read the contents of repositories.

Demo

2-nexus-first-signin

Set Up Docker Hosted, Docker Proxy, Docker Group Registries

The Repository Management screen displays a list of configured repositories in your Nexus Repository deployment.

To access the Repository Management screen, navigate to Administration (cog icon) -> Repository -> Repositories.

Docker (Hosted)

This hosted repository is where you can publish internal release in repository using the docker registry format.

Steps to Configure a Hosted for Docker Registry
  1. Click the Create repository to create your repository.
  2. Select docker (hosted) from recipe list.
  3. Define a Name. - e.g. docker-hosted
  4. Enable HTTP repository connector - Check HTTP and put the port number. - e.g. 5001
  5. Enable Docker V1 API support if required by the remote repository
  6. Click Create repository to confirm create your repository.

Docker (Proxy)

This proxy repository accesses the Docker Hub. To reduce duplicate downloads and improve download speeds for your developers and CI servers, you should proxy any registry you use for Docker images.

Steps to Configure a Proxy for Docker Registry
  1. Click the Create repository to create your repository.
  2. Select docker (proxy) from recipe list.
  3. Define a Name. - e.g. docker-proxy
  4. Enable HTTP repository connector - Check HTTP and put the port number. - e.g. 5002
  5. Enable Docker V1 API support if required by the remote repository.
  6. Define the URL for Remote Storage as https://registry-1.docker.io and select Use Docker Hub as Docker Index.
  7. Click Create repository to confirm create your repository.

Docker (Group)

This group commbines the docker formatted repositories docker-hosted and docker-proxy into a single repository for your docker registry

Steps to Configure a Group for Docker Registry
  1. Click the Create repository to create your repository.
  2. Select docker (group) from recipe list.
  3. Define a Name. - e.g. docker-group
  4. Enable HTTP repository connector - Check HTTP and put the port number. - e.g. 5000
  5. Enable Docker V1 API support if required by the remote repository.
  6. Add docker-hosted and docker-proxy as member of repositories.
  7. Click Create repository to confirm create your repository.

Demo

3-nexus-create-docker

Push & Pull Docker Image

Now, we are ready to push & pull our docker image from internal and Docker Hub.

Authenticated Access to Docker Repositories

Login docker-group registry

1
2
3
4
$ docker login 127.0.0.1:5000
Username: admin
Password: P@ssw0rd
Login Succeeded

Login docker-hosted registry

1
2
3
4
$ docker login 127.0.0.1:5001
Username: admin
Password: P@ssw0rd
Login Succeeded

Login docker-proxy registry

1
2
3
4
$ docker login 127.0.0.1:5002
Username: admin
Password: P@ssw0rd
Login Succeeded

Pull Docker Image from Docker Hub

Pull official redis Docker image from docker-group registry.

1
2
3
4
5
6
7
8
9
10
11
12
13
$ docker pull 127.0.0.1:5000/redis
Using default tag: latest 
latest: Pulling from redis 
f11c1adaa26e: Pull complete 
41f83d877c13: Pull complete
20771c9a20a: Pull complete
29b87d971a8: Pull complete
289008bce010: Pull complete
7a8c9f3e2419: Pull complete
4f4fb700f54: Pull complete
09ade157f71: Pull complete
Digest: sha256:fb534a3ac2034a6374933467d971fbcbfa5d213805507f560d564851a720355
Status: Downloaded newer image for 127.0.0.1:5000/redis: latest 127.0.0.1:5000/redis:latest

Pull official redis docker image from docker-hosted registry. You cannot pull Docker Hub image from docker-hosted registry; it is only for internal Docker image.

1
2
3
$ docker pull 127.0.0.1:5001/redis
Using default tag: latest
Error response from daemon: manifest for 127.0.0.1:5001/redis:latest not found: manifest unknown: manifest unknown

Pull official redis Docker image from docker-proxy registry.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ docker pull 127.0.0.1:5002/redis
Using default tag: latest
latest: Pulling from redis
f11c1adaa26e: Pull complete
41f83d877c13: Pull complete
20771cb9a20a: Pull complete
29b87d971a8: Pull complete
289008bce010: Pull complete
7a8c9f32419: Pull complete
4f4fb700f54: Pull complete
09ade1b57f71: Pull complete
Digest: sha256:fb534a36ac2034a6374933467d971fbcbfa5d213805507f560d564851a720355
127.0.0.1:5002/redis:latest
Status: Downloaded newer image for 127.0.0.1:5002/redis:latest

Push Your Docker Image

Push your docker image to docker-group registry. You are not allowed to do so; it is only a feature for PRO-licensed users.

1
2
3
4
5
$ docker push 127.0.0.1:5000/apline-curl:1.0.0
The push refers to repository [127.0.0.1:5000/apline-curl]
425514831c0: Preparing
4693057c236: Preparing
denied: Deploying to groups is a PRO-licensed feature. See https://links.sonatype.com/product-nexus-repository

Push your docker image to docker-hosted registry.

1
2
3
4
5
$ docker push 127.0.0.1:5001/apline-curl:1.0.0
The push refers to repository [127.0.0.1:5001/apline-curl]
425514831c0: Pushed
4693057c236: Pushed
1.0.0: digest: sha256:b0e96b90ca0470d0565ce3d2286b80641630b0588c673e9bebdb375e9f6290 size: 739

Push your docker image to docker-proxy registry. You cannot push yoir Docker image to docker-proxy registry; it is only for accessing Docker Hub images.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ docker push 127.0.0.1:5002/apline-curl:1.0.0
The push refers to repository [127.0.0.1:5002/apline-curl]
425514831c0: Preparing
4693057c236: Preparing
error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "\n<!DOCTYPE html> \n<html lang=\*e 
n\">\n<head›\n <title>404 - Sonatype Nexus Repository‹/title>\n ‹meta http-equiv=\"Content-Type\" content=\"text/html; chars 
et-UTF-8\™/>\n\n\n <link rel=\"icon\" type=\"image/png\" href=\"../../../../../../static/rapture/resources/safari-favicon-32x
32.png?3.70.1-02\" sizes=\"32x32\">\n <link rel-\"mask-icon\™ href=\"../../../../../../static/rapture/resources/favicon-white
-svg?3.70.1-02\™ color=\"#00bb6c\">\n <link rel=\"icon\" type=\"image/png\™ href=\"../../../../../../static/rapture/resources
/favicon.svg?3.70.1-02\" sizes=\"16x16\">\n\n <link rel-\"stylesheet\" type-\"text/css\" href=\".././../../../../static/css/
nexus-content.css?3.70.1-02\*/>\n</head>\n<body>\n<div class=\"nexus-header\">\n ‹a href=\"../../../../../..\">\n    <div cla
55=\"product-logo\"› In <img src=\"../../../../../../static/rapture/resources/nxrm-reverse-icon.png?3.70.1-02\™ alt=\"Prod
uct logo\*/›\n </div›\n ‹div class=\"product-id\"> \n ‹div class=\"product-id_line-1\*>\n <span class=\"product-name\>Sonatype 
Nexus Repository</span> \n</div>\n‹div class=\"product-id_line-2\*> \n‹span class=\"product-spec\"›oss 3.70.1-02</span> \n
</div>\n </div>\n </a>\n</div>\n\n<div class=\"nexus-body\">\n <div class=\"conte</div>\nnt-header\">\n <ing src=\"../../../../
../../static/rapture/resources/icons/x32/exclamation.png?3.70.1-02\™ alt=\"Exclamation point\" aria-role=\"presentation)"/>\n
«span class=\"title\"›Error 404/span>\n ‹span class=\"description\"›Not Found</span> \n </div>\n ‹div class=\"content-body\*> \n
‹div class=\"content-section\">\nNot Found\n‹/div›n </div›\n</div> \n</body> \n</html >\n\n"

Pull Your Docker Image

Pull your Docker image from docker-group registry.

1
2
3
4
5
6
7
8
$ docker pull 127.0.0.1:5000/apline-curl:1.0.0
1.0.0: Pulling from apline-curl
7264a8db6415: Already exists
42509401fald: Already exists
Digest: sha256:b0e96b90ca0470d0565ce3dc2286b80641630b0588bc673e9bebdb375e9f6290
stacus. Downloaded newer lace tor 121.0.0.115000/ abllne-cur1.1.0.0
Status: Downloaded newer image for 127.0.0.1:5000/apline-curl:1.0.0
127.0.0.1:5000/apline-curl:1.0.0

Pull your Docker image from docker-hosted registry.

1
2
3
4
5
$ docker pull 127.0.0.1:5001/apline-curl:1.0.0
1.0.0: Pulling from apline-curl
Digest: sha256: b@e96b90ca0470d0565ce3dc2286b80641630b0588bc673e9bebdb375e9f6290
Status: Downloaded newer image for 127.0.0.1:5001/apline-curl:1.0.0
127.0.0.1:5001/apline-curl:1.0.0

Pull your Docker image from docker-proxy registry. You cannot pull your Docker image from docker-proxy registry; it is only for accessing Docker Hub images.

1
2
$ docker pull 127.0.0.1:5002/apline-curl:1.0.0
Error response from daemon: manifest for 127.0.0.1:5002/apline-curl:1.0.0 not found: manifest unknown: manifest unknown

Check Push Docker Images via User Interface

Navigate to Administration (cog icon) -> Repository -> Repositories

Click docker-group from the Repositories list

4-docker-group

Click docker-hosted from the Repositories list

5-docker-hosted

Click docker-proxy from the Repositories list

6-docker-proxy

Push & Pull NuGet Package

Set Up NuGet Registry

By default NuGet Registries are created when Nexus OSS start up. To access the Repository Management screen, navigate to Administration (cog icon) -> Repository -> Repositories. nuget-group, nuget-hosted and nuget.org-proxy created.

7-nexus-nuget

Authenticated Access to Nuget Repositories

To authenticate a client against a NuGet repository, NuGet uses an API key for deployment requests. This API key serves as an alias for the user account and is utilized across all NuGet repositories within the repository manager. The user generates this key, which can be regenerated at any time. When a new key is created, all previous keys for that user become invalid. This process ensures secure and consistent access to the NuGet repositories, tying the key directly to the user’s account and maintaining security through key regeneration.

  1. To access the Repository Management screen, navigate to Administration (cog icon) -> Security -> Realms.
  2. Add NuGet API-Key Realm from Available list to Active list.
  3. Click Save button.
  4. Click the admin button in the top right of the page.
  5. Click NuGet API Key button.
  6. Click Access API Key button and then click Copy to Chipboard button to copy access api key.

Demo

8-nexus-nuget

Add New NuGet Package Source in Visual Studio

  1. Load a project in Solution Explorer, and select Tool -> NuGet Package Manager -> Package Manager Settings to open the Options windows opens.
  2. Select the Package Source under NuGet Package Manager
  3. Click + to add new NuGet Package Source
  4. Name - Nexus and Source - http://127.0.0.1:8081/repository/nuget-group/index.json

9-vs-nuget-setup-1

10-vs-nuget-setup-2

Push NuGet Package

Go to the folder of your NuGet package and type following command to push your NuGet package to Nexus

1
$ dotnet nuget push -s <nexus nuget repository link> -k <nuget apikey> <your nuget package>.nupkg
Demo
1
2
3
4
5
6
$ dotnet nuget push -s http://127.0.0.1:8081/repository/nuget-hosted/ -k 1e1f2347-349b-3c89-b03e-4e977742f04d jasonlws-library.1.0.0.nupkg
Pushing jasonlws-library.1.0.0.nupkg to 'http://127.0.0.1:8081/repository/nuget-hosted/'...
warn : You are running the 'push' operation with an 'HTTP' source, 'http://127.0.0.1:8081/repository/nuget-hosted/'. Non-HTTPS access will be removed in a future version. Consider migrating to an 'HTTPS' source.
  PUT http://127.0.0.1:8081/repository/nuget-hosted/
  Created http://127.0.0.1:8081/repository/nuget-hosted/ 81ms
Your package was pushed.

Pull NeGet Package

To find and install a NuGet package with Visual Studio from Nexus, follow these steps:

  1. Load a project in Solution Explorer, and then select Project > Manage NuGet Packages to open the NuGet Package Manager windows opens.
  2. Select Nexus from Package source list.
  3. Select the Browse tab to display packages by popularity from the currently selected source (see Package sources). You can see previous pushed NuGet package from the list.

11-vs-nuget

References

  • Sonatype Nexus Repository - link
  • About Myself

Please reach out to connect with me via Linkedin.

This post is licensed under CC BY 4.0 by the author.