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.
Format | Description |
---|---|
APT | Use Advanced Package Tool (APT) tools such as apt-get to access hosted Debian, Ubuntu and other Linux software packages. |
Bower | Keep track of all your web site frontend development packages using Bower registries. Note that Bower format is not compatible with H2 or PostgreSQL databases. |
CocoaPods | Manager for CocoaPods packages (which might contain Swift code) and Objective-C Cocoa projects. Note that we do not support Apple’s Swift package manager. |
Conan | Share your C/C++ packages in a central repository. |
Conda | Proxy Conda packages for languages such as Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++ and FORTRAN. |
Docker | Proxy popular Docker registries such as DockerHub and host your own private images securely. |
Git LFS | Store large files such as audio samples, videos, datasets, and graphics inside repositories and use simple text pointers to these inside your Git project. |
Go | Modernize your development process and store Go (golang) dependencies for fast, repeatable local builds. |
Helm | Manage packages for Kubernetes by accessing Helm Charts in Helm repositories. |
Maven | Leverage 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. |
npm | Publish your javascript node.js projects to hosted registries and integrate dependencies from external JavaScript package registries. |
NuGet | Use NuGet client compatible tooling to push and install .Net packages. Development is easier using consolidated hosted and proxy registries. |
p2 | Proxy p2 format repositories for your Eclipse IDE and other Equinox based application dependencies. |
PyPI | Python development tools such as pip and twine can be used install and publish packages to PyPI repositories. |
R | Proxy packages from the official R registry and host your own packages. |
Raw | A 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. |
RubyGems | Host your own gems and proxy remote gem repositories like rubygems.org. |
Yum | First 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
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
- Click the Create repository to create your repository.
- Select docker (hosted) from recipe list.
- Define a Name. - e.g.
docker-hosted
- Enable HTTP repository connector - Check HTTP and put the port number. - e.g.
5001
- Enable Docker V1 API support if required by the remote repository
- 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
- Click the Create repository to create your repository.
- Select docker (proxy) from recipe list.
- Define a Name. - e.g.
docker-proxy
- Enable HTTP repository connector - Check HTTP and put the port number. - e.g.
5002
- Enable Docker V1 API support if required by the remote repository.
- Define the URL for Remote Storage as
https://registry-1.docker.io
and selectUse Docker Hub
as Docker Index. - 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
- Click the Create repository to create your repository.
- Select docker (group) from recipe list.
- Define a Name. - e.g.
docker-group
- Enable HTTP repository connector - Check HTTP and put the port number. - e.g.
5000
- Enable Docker V1 API support if required by the remote repository.
- Add
docker-hosted
anddocker-proxy
as member of repositories. - Click Create repository to confirm create your repository.
Demo
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
Click docker-hosted
from the Repositories list
Click docker-proxy
from the Repositories list
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.
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.
- To access the Repository Management screen, navigate to Administration (cog icon) -> Security -> Realms.
- Add
NuGet API-Key Realm
from Available list to Active list. - Click
Save
button. - Click the
admin
button in the top right of the page. - Click
NuGet API Key
button. - Click
Access API Key
button and then clickCopy to Chipboard
button to copy access api key.
Demo
Add New NuGet Package Source in Visual Studio
- Load a project in
Solution Explorer
, and selectTool
->NuGet Package Manager
->Package Manager Settings
to open the Options windows opens. - Select the
Package Source
underNuGet Package Manager
- Click
+
to add new NuGet Package Source - Name -
Nexus
and Source -http://127.0.0.1:8081/repository/nuget-group/index.json
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:
- Load a project in
Solution Explorer
, and then selectProject
>Manage NuGet Packages
to open the NuGet Package Manager windows opens. - Select
Nexus
fromPackage source
list. - 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.
References
- Sonatype Nexus Repository - link
About Myself
Please reach out to connect with me via Linkedin.