Nexus As Docker Trusted Registry — To Pull / Push Docker Images

Saleem Pasha
4 min readSep 15, 2020

My name is Saleem Pasha Shaik. I hail from Hyderabad ,Telangana. I am a DevOps evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others. At present I work at Jio Platforms Ltd as Manager — DevOps. You can contact me at iamsaleempasha2020@gmail.com

In this exercise, we are going to learn -

  1. Setting up a Nexus Repository Manager.
  2. How to create a Docker Registry under Nexus.
  3. How to pull/push images from/to Nexus Docker Registry.

You had to install the Docker daemon on the box from where you want to generate Docker images.

There are certain occasions during which you may want to publish your images into a private repository instead of a public repository like Dockerhub. The Nexus repository manager comes into the picture here as it can host all types of artifacts starting from jar, war, Docker images, Maven and npm packages, and more.

This exercise assumes you have basic knowledge about Docker and repositories. We will first set up the Nexus repository on a local box followed by setting up the build process to publish the image to the same nexus repository.

Docker

Docker is a lightweight container used for publishing apps with the entire ecosystem packaged in a single bundle.

Nexus

Nexus is a repository manager tool, used for hosting various types of artifacts like jar, War, Maven, npm packages and Docker images.

Prerequisite

There are some prerequisite for this tutorial to be completed.

  1. Download Nexus from below location, you need to choose your operating system version.

https://www.sonatype.com/nexus/repository-oss/download

2. Extract it to a location; call it install_path for example.

3. Start Nexus by running this command as administrator.

# install_path\nexus-3.20.1–01\bin\nexus /run

If step three fails due to port conflict, there will be a file created by Nexus Start called nexus.properties at

#install_path\sonatype-work\nexus3\etc\nexus.properties

You need to change the port to any port non-conflicting port 9081. Note this file will be created only when Nexus starts up successfully

4. Login to Nexus as admin. Your password is in the admin.password file that gets created after the Nexus start up. You need to find the default password for admin, which you can find at this location.

Once you login to the system, click on the “Go to repositories” tab from the left menu and click the “Create repository” button shown below.

Create repository

Create repository

In the second screen, please select “Docker hosted” as a recipe type.

Now enter the registry name and the HTTP port and keep the rest as default and click on the “Create repository” button at the bottom part of the screen.

PLEASE FOLLOW BELOW STEPS TO PULL/PUSH DOCKER IMAGES FROM NEXUS DOCKER REGISTRY :

PF the below Nexus Docker Registry details for the demonstration purpose as follows :

Nexus Server IP : 10.100.40.111 with port 5000

Step 1: We need to make entry in the daemon.json file at the below path

/etc/docker/daemon.json{

“insecure-registries”: [ “10.100.40.111:5000” ]

}

Step 2: After adding the above entry execute below commands

# systemctl daemon-reload

# service docker stop

# service docker start

# service docker status

Step 3: Try to execute below Command to login into Docker Nexus Registry

$ docker login –u <nexususerid> –password ****** 10.100.40.111:5000

Post execution of above 3 steps — If you are still unable to connect to the nexus registry then follow the below steps:

Step 4: Make “NO_PROXY” entry in http-proxy.conf file at below path as below:

$ vi /etc/systemd/system/docker.service.d

Environment=”HTTP_PROXY=http://10.X.X.X:<port>“ “NO_PROXY=localhost,127.0.0.1,10.100.40.111“

Step 5: Execute below commands:

# systemctl daemon-reload

# service docker stop

# service docker start

# service docker status

or

#systemctl restart docker

# service docker status

Step 6: After executing the above steps execute below Command to login into Docker Nexus Registry

$ docker login –u <nexususerid> –password ****** 10.100.40.111:5000

Step 7: Build your Docker Image

$ docker build -t my_firstimage . (execute this command in the path where your Dockerfile exists)

Step 8: Tag your Docker image

$ docker tag my_firstimage 10.100.40.111:5000/my_image

Step 9: Push your Docker image to the Nexus Docker Registry

$ docker push 10.141.51.157:5107/my_image

By completion of this exercise you have learned

  1. Setting up a Nexus repository manager running over HTTP.
  2. You also learned how to create a Docker Registry under Nexus.
  3. Lastly, we also learned how to pull/push images from/to nexus docker registry.

The image built can be used by any Docker client to be run on his/her machine with the help of the docker run command.

Links for your reference:

https://docs.docker.com/registry/insecure/

https://docs.docker.com/config/daemon/systemd/

--

--

Saleem Pasha

My name is Saleem Pasha. I hail from Hyderabad ,Telangana. I am a DevOps evangelist who believes in Hard work, A down to earth person, Likes to share knowledge.