A short time back, I showed you how to change the Project Harbor configuration to use persistent storage provided by docker volume driver for vSphere and save your images on Virtual SAN. In this post, I will show you how to use Project Harbor by adding a new user to Harbor, create a new project for this user, login to Harbor via docker, and then push and pull image from the Project Harbor repo. While these instructions are simplified just to get you started, you should refer to the official project hard documentation which is available on the github site. The user guide can be found here.

Step 1: Verify UI Login is successful

The default credentials are admin/harbor12345. These can be changed once logged in. But at the very least you should check that you can login here before trying to push/pull images.

Step 2: Create a new user (if desired)

I decided to create a new user called ops for this demo.

I then verified that I could login as that user – always a good thing to do 🙂

Step 3: Create a project for the new user

I called the project “ops-repo”. My images will appear here. By the way, even if you are using an admin user, you will still need to create a project.

It is now time to push and pull images to this repo. This is done from the docker command line.

Step 4: Set login to use port 80

In the following output, you can see a number of attempts to login to the registry. The first thing I did was to create a DOCKER_OPTS environment variable which enables insecure access on port 80. You can see initially that the login is attempted on port 443. On restarting docker, it attempts port 80, but it is only after doing a docker-compose down, then up, that the login actually succeeds. These initial tests were done with the admin user.

# env | grep DOCKER DOCKER_OPTS=--insecure-registry 10.27.51.39 # docker login -u admin -p harbor12345 10.27.51.39 Error response from daemon: Get https ://10.27.51.39/v1/users/: dial tcp 10.27.51.39: 443 : getsockopt: connection refused # systemctl restart docker # docker login -u admin -p harbor12345 10.27.51.39 Error response from daemon: Get http ://10.27.51.39/v1/users/: dial tcp 10.27.51.39: 80 : getsockopt: connection refused # docker-compose down Removing deploy_proxy_1 ... done Removing deploy_jobservice_1 ... done Removing deploy_mysql_1 ... done Removing deploy_registry_1 ... done Removing deploy_ui_1 ... done Removing deploy_log_1 ... done Removing network deploy_default # docker-compose up -d Creating network "deploy_default" with the default driver Creating deploy_log_1 Creating deploy_ui_1 Creating deploy_mysql_1 Creating deploy_registry_1 Creating deploy_jobservice_1 Creating deploy_proxy_1 # docker login -u admin -p harbor12345 10.27.51.39 Login Succeeded

Login is now working. Let’s try to push an image to the repo using docker push.

Step 5: Push an image to the repo in Project Harbor

In this example, I am pulling down an image called nginx from the docker hub, tagging it, and pushing it out to my Project Harbor repo:

# docker pull nginx Using default tag: latest latest: Pulling from library/nginx 51f5c6a04d83: Already exists a3ed95caeb02: Pull complete 51d229e136d0: Pull complete bcd41daec8cc: Pull complete Digest: sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04 Status: Downloaded newer image for nginx:latest # docker images | grep nginx | grep latest nginx latest 0d409d33b27e \ 9 weeks ago 182.7 MB # env | grep DOCKER DOCKER_OPTS=--insecure-registry 10.27.51.39 # docker login -u ops 10.27.51.39 Password: Login Succeeded # docker tag 0d409d33b27e cormac-nginx:latest # docker tag cormac-nginx:latest 10.27.51.39/ops-repo/cormac-nginx:latest # docker push 10.27.51.39/ops-repo/cormac-nginx:latest The push refers to a repository [10.27.51.39/ops-repo/cormac-nginx] 5f70bf18a086: Mounted from corproj1/cormac-nginx bbf4634aee1a: Mounted from corproj1/cormac-nginx 64d0c8aee4b0: Mounted from corproj1/cormac-nginx 4dcab49015d4: Mounted from corproj1/cormac-nginx latest: digest: \ sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04\ size: 1956 # # docker images | grep cormac 10.27.51.39/ops-repo/cormac-nginx latest 0d409d33b27e \ 9 weeks ago 182.7 MB

Step 6: Review repo on UI

We can now see the image in our repo in Project Harbor.

Step 7: Pull the image from Project Harbor

In this example, I will remove the image locally, and then pull it from the Project Harbor repo.

# docker images | grep cormac 10.27.51.39/ops-repo/cormac-nginx latest \ 0d409d33b27e 9 weeks ago 182.7 MB # docker rmi -f 0d409d33b27e Untagged: 10.27.51.39/ops-repo/cormac-nginx:latest Untagged: nginx:latest Deleted: sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470d Deleted: sha256:894e1c82ec1396d0d30c0f710d0df5ae5f8dc543e53cca3f92d305fe09370282 Deleted: sha256:26fdf3d8f16c52bcf3c6b363739bda3c9531e394427d09d7118446914eedae02 Deleted: sha256:2254f56d1c260b47ea426e484164f7ef161310ef7d8a089d3a2f86a31fcd575f Deleted: sha256:f75463f4fa42454f52336dcab2c98ed51c3466db347c2bc4e210d708645e77f2 # docker images | grep cormac # docker pull 10.27.51.39/ops-repo/cormac-nginx:latest latest: Pulling from ops-repo/cormac-nginx 51f5c6a04d83: Already exists a3ed95caeb02: Pull complete 51d229e136d0: Pull complete bcd41daec8cc: Pull complete Digest: sha256:0fe6413f3e30fcc5920bc8fa769280975b10b1c26721de956e1428b9e2f29d04 Status: Downloaded newer image for 10.27.51.39/ops-repo/cormac-nginx:latest # docker images | grep cormac 10.27.51.39/ops-repo/cormac-nginx latest \ 0d409d33b27e 9 weeks ago 182.7 MB #

Step 8: Do the images still work?

Let’s fire up the nginx image. I chose port 8000 as the port map since Project Harbor is already running another nginx image on port 80.

# docker run -d -p 8000:80 0d409d33b27e 82759d82e6dc0917ea519ffd96866a67c6b28dc124892b1b647532f61257cf47 #

Looks good to me!