Harbor的搭建过程比较简单,从官网下载镜像解压、配置、安装即可:
harbor-offline-installer-0.5.0.tgz
安装完成后,我们先尝试登陆Harbor:
root@docker:~# docker login 192.168.1.132
Username:
Password:
Error response from daemon: Get https://192.168.1.132/v1/users/: dial tcp 192.168.1.132:443: getsockopt: connection refused
这时需要配置所在主机的docker:
配置下面两个参数:
EnvironmentFile=-/etc/default/docker
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
然后在”/etc/default/docker”中添加:
DOCKER_OPTS=”–insecure-registry 192.168.1.132”
重启docker再次登陆即可成功。
接下来向Harbor推一个镜像:
1、首先在Harbor上创建一个项目”common”。
2、查看本地的镜像:
root@docker:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 98d35105a391 2 weeks ago 192.5 MB
ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
3、给”ubuntu”这个镜像打上tag:
docker tag ubuntu 192.168.1.132/common/ubuntu
4、推送至Harbor:
root@docker:~# docker push 192.168.1.132/common/ubuntu
The push refers to a repository [192.168.1.132/common/ubuntu]
56827159aa8b: Pushed
440e02c3dcde: Pushed
29660d0e5bb2: Pushed
85782553e37a: Pushed
745f5be9952c: Pushed
latest: digest: sha256:dd7808d8792c9841d0b460122f1acf0a2dd1f56404f8d1e56298048885e45535 size: 1357
5.在Harbor上common项目下可以看到这个镜像
6.拉取上传的镜像
尝试”docker search”上传的镜像报”Error response from daemon: Unexpected status code 404”,在网上查到” there is no search in the v2 protocol yet.”?
直接下载这个镜像:
root@i-r7cnd8iq:~# docker pull 192.168.1.132/common/ubuntu
Using default tag: latest
latest: Pulling from common/ubuntu
d54efb8db41d: Pull complete
f8b845f45a87: Pull complete
e8db7bf7c39f: Pull complete
9654c40e9079: Pull complete
6d9ef359eaaa: Pull complete
Digest: sha256:dd7808d8792c9841d0b460122f1acf0a2dd1f56404f8d1e56298048885e45535
Status: Downloaded newer image for 192.168.1.132/common/ubuntu:latest
root@i-r7cnd8iq:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.1.132/common/ubuntu latest 0ef2e08ed3fa 4 weeks ago 130 MB
补充:
1.关于配置“–insecure-registry harbor.test.com”参数:
配置这个参数后docker向harbor.test.com推镜像时,允许使用http协议。
如果在推送时仍出现下面的情况:
docker push harbor.test.com/kubernetes_images/nginx-ingress-controller:0.9.0-beta.5
The push refers to a repository [harbor.test.com/kubernetes_images/nginx-ingress-controller]
f42419eb2ef1: Retrying in 1 second
84c21a15bb21: Retrying in 1 second
763df6c29bf9: Retrying in 1 second
f4b65ff55cc1: Retrying in 1 second
bfdde1cc117f: Retrying in 1 second
5c5d2148f4b3: Retrying in 5 seconds
58995c8cef42: Waiting
Error: Status 503 trying to push repository kubernetes_images/nginx-ingress-controller: "<html><body><h1>503 Service Unavailable</h1>\nNo server is available to handle this request.\n</body></html>\n\n"
这可能是harbor.test.com前面的路由器或者负载均衡器监听了443端口,这时查看日志会出现:
May 5 14:58:02 docker dockerd-current: time="2017-05-05T14:58:02.225826798+08:00" level=error msg="Attempting next endpoint for push after error: Get https://harbor.test.com/v2/: dial tcp 119.111.111.111:443: getsockopt: connection refused"
还是请求了443端口,并等待相应。so,如果出现这样的情况,检查harbor前面的路由器或负载均衡器。