1. Harbor service bind host
[root@localhost harbor]# vi /etc/hosts
[root@localhost harbor]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.10.8 harbor.olive.org
复制代码
2. Log in to Harbor mirror warehouse
[root@localhost harbor]# docker login harbor.olive.org
Username: admin
Password:
Error response from daemon: Get "https://harbor.olive.org/v2/": dial tcp 192.168.10.8:443: connect: connection refused
复制代码
The above connection refused error occurs because when using docker's warehouse, Registry requires https certificate support by default for security reasons. In addition to generating a certificate and configuring https; in the experimental environment, it can also be solved by modifying the docker configuration file daemon.json to add the Harbor
**** address to the Docker
**** trust list.
/etc/docker/daemon.json
It is the configuration file of docker. It is not available by default and needs to be created manually. The following configuration can be performed:
vi /etc/docker/daemon.json
复制代码
Add the insecure-registries field and add your own ip or domain name to the list
{
"insecure-registries": ["http://harbor.olive.org"]
}
复制代码
Restart docker after modification
#重新获取配置
systemctl daemon-reload
#重新启动docker
systemctl restart docker
复制代码
After restarting docker, you may encounter the situation that Harbor cannot be accessed normally; this is because after docker restarts, Harbor-related containers are not automatically started, as long as all Harbor containers are restarted, it is best to start the harbor-log container first .
It can be restarted docker restart containerID
one by one , or with docker-compose:
[root@localhost harbor]# cd /usr/local/harbor
[root@localhost harbor]# docker-compose stop
[root@localhost harbor]# docker-compose up -d
复制代码
This Harbor start and stop operation must operate the above commands in Harbor's installation directory, otherwise docker-compose.yml
an error of not being found will be reported.
Login to Harbor again
[root@localhost harbor]# docker login harbor.olive.org
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[root@localhost harbor]#
复制代码
3. Push the image to the Harbor repository
- mirror tagging
docker tag centos-jre8:v1.0 harbor.olive.org/omg/centos-jre8:v1.0
复制代码
centos-jre8:v1.0
It is composed of REPOSITORY+TAG in the following figure ; use the docker images
command to view
- Create a project in Harbor
- push image
docker push harbor.olive.org/omg/centos-jre8:v1.0
复制代码
Mirror push is performed without creating a project in Harbor; the following error occurs: The omg project cannot be found
[root@localhost harbor]# docker push harbor.olive.org/omg/centos-jre8:v1.0
The push refers to repository [harbor.olive.org/omg/centos-jre8]
6575c18211a0: Preparing
15836fdef74a: Preparing
174f56854903: Preparing
unauthorized: project omg not found: project omg not found
复制代码
After creating the project, push
[root@localhost harbor]# docker push harbor.olive.org/omg/centos-jre8:v1.0
The push refers to repository [harbor.olive.org/omg/centos-jre8]
6575c18211a0: Pushed
15836fdef74a: Pushed
174f56854903: Pushed
v1.0: digest: sha256:3cba5aaf993441fb237ab950b2d207ee624a801dd031ecb35e8f72ef03e99cb4 size: 948
复制代码
4. Pull the image from the Harbor repository
- Login first
docker login -u admin -p Harbor123 harbor.olive.org
复制代码
- pull image
docker pull harbor.olive.org/omg/centos-jre8:v1.0
复制代码
另外拉取镜像的地址也可以在如下 Harbor 界面找到
这里复制出来的是ip,如果使用这个拉取命令,需要修改一下/etc/docker/daemon.json
;insecure-registries
字段增加 ip。\
docker pull 192.168.10.8/omg/centos-jre8@sha256:3cba5aaf993441fb237ab950b2d207ee624a801dd031ecb35e8f72ef03e99cb4
复制代码
5. 登出 Harbor 镜像仓库
[root@localhost harbor]# docker logout harbor.olive.org
Removing login credentials for harbor.olive.org
复制代码