Method steps for creating an Docker repository using Nexus

  • 2021-07-18 09:26:51
  • OfStack

The warehouse created by Docker official Registry is faced with such problems, for example, the space will not be recycled by default after deleting the image, resulting in the space being occupied. A common practice is to use Nexus to manage enterprise toolkits.

Nexus can not only create Docker repositories, but also NPM, Maven and other types of repositories.

Start the Nexus container


$ docker run -d --name nexus3 --restart=always \
  -p 8081:8081 \
  -p 8082:8082 \
  --mount src=nexus-data,target=/nexus-data \
  sonatype/nexus3
Unable to find image 'sonatype/nexus3:latest' locally
latest: Pulling from sonatype/nexus3
c65691897a4d: Pull complete
641d7cc5cbc4: Pull complete
c508b13320cd: Pull complete
79e3bf9d3132: Pull complete
Digest: sha256:2c33632ccd8f8c5f9023a3d7f5f541e271833e402219f8c5a83a29d1721457ca
Status: Downloaded newer image for sonatype/nexus3:latest
f637e039214978f8aac41e621e51588bd8cd8438055498c4060fbaf87799e64f

Among them, 8081 is the access port of Nexus, and 8082 is the port of warehouse. Most articles on the Internet do not add the mapping of 8082 port, which leads to my card for a long time when testing.

Wait a minute or two, and the browser opens domain: 8081.

Click Sign in in the upper right corner to log in. The initial account number is admin. The password can enter the container through exec command, and view the initial password according to the prompted path.

Enter the container to view the initial password


$ docker exec -it f637 /bin/bash
bash-4.4$ vi /nexus-data/admin.password

After logging in, you will be asked to change your password, and you will use this password in the future.

Create a warehouse

Click the navigation gear button to enter the setup page and enter Repository- > Repositories Click Create repository Select docker (hosted)

docker (hosted) for the local warehouse, docker (proxy) for the proxy warehouse, docker (group) for the aggregation warehouse, this article only introduces the local warehouse, if you are interested can also find the use of the other two warehouses online.

Just fill in the red box in the above figure, where Name is the warehouse name, and the input box of HTTP is to fill in the port number 8082. After writing, slide to the bottom of the page and click Create repository to create the warehouse.

Add Access Permissions

Menu Security- > Realms Save Docker Bearer Token Realm in the box on the right.

Add User Rules: Menu Security- > Roles- > Create role Search docker in the Privlleges option Move the corresponding rule to the box on the right and save it.

Add users: Menu Security- > Users- > Create local user Select the rule you just created in the Roles option and move to the right window to save.

Login Warehouse

Because the created repository is accessed by HTTP, you need to modify Daemon in Docker configuration before logging in

{ "insecure-registries": ["domain:8082"] }


$ docker login domain:8082
Username: yourName
Password:
Login Succeeded

Upload warehouse, download warehouse and search warehouse, which are related to 1 in the previous article, will not be repeated here.

One of the important points to note is that when starting Nexus, you need to map port 1 of the warehouse to the host machine.


Related articles: