Nexus3 private warehouse construction docker + Maven + NPM

Time:2022-5-25

install

Nexus is known as the most popular private server management software in the world. It can build almost all common warehouses, such as NPM, maven, yum, etc. nexus 3 adds support for docker warehouse, which should be the only choice to build private servers

Nexus has two versionsNexus Repository OSSandNexus Repository ProThe OSS version is free and the pro professional version needs to be charged OSS is sufficient for daily warehouse management

Nexus OSS supports binary file installation and docker installation. Docker installation is simple and convenient

Run the following command to complete the installation

$ docker run -d -p 8081:8081 sonatype/nexus3
#You can mount the local directory for data persistence
$ mkdir /some/dir/nexus-data && chown -R 757 /some/dir/nexus-data
$ docker run -d -p 8081:8081 -v /some/dir/nexus-data:/nexus-data sonatype/nexus3

staynexus3The permissions set for the mounting directory in the official docker warehouse instruction document are200However, it cannot be started during actual installation, and the permission is insufficient. The error is as follows:

mkdir: cannot create directory '../sonatype-work/nexus3': Permission denied
mkdir: cannot create directory '../sonatype-work/nexus3': Permission denied
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to Permission denied

Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
Unable to update instance pid: Unable to create directory /nexus-data/instances
/nexus-data/log/karaf.log (Permission denied)
Unable to update instance pid: Unable to create directory /nexus-data/instances
Exception in thread "Thread-2" java.lang.SecurityException: Could not lock User prefs. Lock file access denied.
    at java.util.prefs.FileSystemPreferences.checkLockFile0ErrorCode(FileSystemPreferences.java:937)
    at java.util.prefs.FileSystemPreferences.lockFile(FileSystemPreferences.java:925)
    at java.util.prefs.FileSystemPreferences.sync(FileSystemPreferences.java:729)
    at java.util.prefs.FileSystemPreferences.flush(FileSystemPreferences.java:824)
    at java.util.prefs.FileSystemPreferences.syncWorld(FileSystemPreferences.java:464)
    at java.util.prefs.FileSystemPreferences.access$1200(FileSystemPreferences.java:50)
    at java.util.prefs.FileSystemPreferences$4$1.run(FileSystemPreferences.java:442)

Change to757Start normally after Wait for the start-up to complete, accesshttp://host:8081Test for successful installation

Nextus3 build docker private warehouse

There are three types of nextus3 warehouses

  1. The submission and pull of hosted (local type) assets are based on local storage
  2. Proxy (proxy type) does not store data locally and can cooperate with hosted
  3. Group (combination type) can combine multiple hosted and proxies in order, and provide a unified access address

Docker local warehouse (hosted)

  1. visithttp://host:8081Login, default user name and password admin / admin123
  2. clickRepository->Blob Stores->Create blob storeCreate local storage
Type:file
Name:definesys-docker-store
Path:/nexus-data/blobs/definesys-docker-store

Because you want to store images, please ensure that there is enough space in this directory, which can be attached to NAS

  1. clickRepositories->Create repositories->docker(hosted)Create local warehouse
Name (warehouse name): definesys docker repo
HTTP (warehouse open port): 8001
Docker registry API support: must be selected
Storage: select the definesys docker store you just created
Other options can be selected by default

This completes the creation of a docker private warehouse, and the process is still very simple

Construction of docker proxy warehouse

  1. clickRepositories->Create repositories->docker(proxy)Create agent warehouse
Name (warehouse name): definesys docker proxy
HTTP (warehouse open port): 8002
Docker registry API support: must be selected
Proxy->remote storage:https://registry-1.docker.io/
Docker index select use docker hub
Storage: select the newly created definesys docker store, so that it can share a storage with hosted to achieve local priority and local pull. If it cannot be found locally, it can be pulled from the remote warehouse
Other options can be selected by default

Construction of docker group warehouse

Name (warehouse name): definesys docker group
HTTP (warehouse open port): 8003
Docker registry API support: must be selected
Storage: select the definesys docker store you just created
Group:
definesys-docker-repo
definesys-docker-proxy
Other options can be selected by default

Docker client configuration

  1. editdaemon.jsonfile
$ vi /etc/docker/daemon.json
{
    "insecure-registries": [
        "http://localhost:7001",
        "http://localhost:7002",
        "http://localhost:7003"
    ],
    "disable-legacy-registry": true
}
  1. Restart docker
$ systemctl restart docker
  1. Start the nexus3 container and map the three ports to the host
$ docker run -d -p 8081:8081 -p 8001:8001 -p 8003:8003 -p 8002:8002  -v /root/u01/nexus-data:/nexus-data sonatype/nexus3

4. Log in to three warehouses respectively

$ docker login -u admin -p admin123 http://localhost:8001
$ docker login -u admin -p admin123 http://localhost:8002
$ docker login -u admin -p admin123 http://localhost:8003

Nexus will record the login information in~/.docker/config.json, so you don’t have to log in again next time:

{
        "auths": {
                "http://localhost:8003": {
                        "auth": "YWRtaW46YWRtaW4xMjM="
                },
                "http://localhost:8001": {
                        "auth": "YWRtaW46YWRtaW4xMjM="
                },
                "http://localhost:8002": {
                        "auth": "YWRtaW46YWRtaW4xMjM="
                }
        }
}

Docker image upload

  1. Tag the local image (take Ubuntu image as an example here) and upload it to the hosted warehouse (8001)
$ docker tag docker.io/ubuntu:15.10 localhost:8001/defiensys-ubuntu:15.10
$ docker push localhost:8001/defiensys-ubuntu:15.10
  1. Log in to nexus3 to view the results

Docker image pull

  • Through group warehouse
#Pull the image on docker hub
$ docker pull localhost:8003/mysql
#Pull private server image
$ docker pull localhost:8003/defiensys-ubuntu:15.10

Nextus3 build Maven private warehouse

To be continued

Nextus3 build NPM private warehouse

To be continued

remaining problems

  1. Unable to upload the image through group. The following error is reported
$ docker push localhost:8003/oraclelinux:v1.0
The push refers to a repository [localhost:8003/oraclelinux]
3b431d8f4cd1: Preparing
error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "\n<!DOCTYPE html>\n<html>\n<head>\n  <title>404 - Nexus Repository Manager</title>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>\n\n\n  <!--[if lt IE 9]>\n  <script>(new Image).src=\"http://localhost:8003/favicon.ico?3.13.0-01\"</script>\n  <![endif]-->\n  <link rel=\"icon\" type=\"image/png\" href=\"http://localhost:8003/favicon-32x32.png?3.13.0-01\" sizes=\"32x32\">\n  <link rel=\"mask-icon\" href=\"http://localhost:8003/safari-pinned-tab.svg?3.13.0-01\" color=\"#5bbad5\">\n  <link rel=\"icon\" type=\"image/png\" href=\"http://localhost:8003/favicon-16x16.png?3.13.0-01\" sizes=\"16x16\">\n  <link rel=\"shortcut icon\" href=\"http://localhost:8003/favicon.ico?3.13.0-01\">\n  <meta name=\"msapplication-TileImage\" content=\"http://localhost:8003/mstile-144x144.png?3.13.0-01\">\n  <meta name=\"msapplication-TileColor\" content=\"#00a300\">\n\n  <link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8003/static/css/nexus-content.css?3.13.0-01\"/>\n</head>\n<body>\n<div class=\"nexus-header\">\n  <a href=\"http://localhost:8003\">\n    <div class=\"product-logo\">\n      <img src=\"http://localhost:8003/static/images/nexus.png?3.13.0-01\"/>\n    </div>\n    <div class=\"product-id\">\n      <div class=\"product-id__line-1\">\n        <span class=\"product-name\">Nexus Repository Manager</span>\n      </div>\n      <div class=\"product-id__line-2\">\n        <span class=\"product-spec\">OSS 3.13.0-01</span>\n      </div>\n    </div>\n  </a>\n</div>\n\n<div class=\"nexus-body\">\n  <div class=\"content-header\">\n    <img src=\"http://localhost:8003/static/rapture/resources/icons/x32/exclamation.png?3.13.0-01\"/>\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\">\n      Not Found\n    </div>\n      </div>\n</div>\n</body>\n</html>\n\n"