Harbor私有仓库搭建

  • Post author:
  • Post category:Kubernetes
  • Page Views 379 阅读

1.安装docker与docker-compose

docker-compose安装如下:

curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -v 查看版本

2.离线安装harbor

下载离线包:https://github.com/goharbor/harbor/releases

解压有如下文件

[root@CentOS7 harbor]# ll
total 662128
-rw-r--r--. 1 root root 3398 Feb 10 14:18 common.sh
-rw-r--r--. 1 root root 677974489 Feb 10 14:19 harbor.v1.10.1.tar.gz
-rw-r--r--. 1 root root 5888 Feb 14 15:23 harbor.yml
drwxr-xr-x. 2 root root 4096 Feb 14 15:24 input
-rwxr-xr-x. 1 root root 2284 Feb 10 14:18 install.sh
-rw-r--r--. 1 root root 11347 Feb 10 14:18 LICENSE
-rwxr-xr-x. 1 root root 1749 Feb 10 14:18 prepare

编辑harbor.yml,修改hostname为本机IP地址,如果没有ssl证书,需注释掉相关https的配置,如下:

[root@CentOS7 harbor]# cat harbor.yml
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: 192.168.244.139
# http related config
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 80
# https related config
#https:
# https port for harbor, default is 443
# port: 443
# The path of cert and key files for nginx
# certificate: /your/certificate/path
# private_key: /your/private/key/path

先运行./prepare,后运行./install.sh,进行安装,出现以下提示说明安装成功

...
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----
[root@CentOS7 harbor]#

3.登陆

Docker自从1.3.X之后docker registry交互默认使用的是https,但是搭建私有镜像默认使用的是http服务,交互时会出现以下错误:

[root@CentOS7 harbor]# docker login 192.168.244.139
Username: admin
Password:
Error response from daemon: Get https://192.168.244.139/v2/: dial tcp 192.168.244.139:443: connect: connection refused

解决办法,在/etc/docker/daemon.json(默认没有,可自行创建),添加如下内容:

[root@CentOS7 ~]# cat /etc/docker/daemon.json
{
"insecure-registries": [ "192.168.244.139" ]
}
[root@CentOS7 ~]# systemctl daemon-reload
[root@CentOS7 ~]# systemctl restart docker

重新登陆

[root@CentOS7 harbor]# docker login 192.168.244.139
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

4.Push镜像

需要注意的是push的镜像需要固定的格式,一般为:主机IP/项目号/IMAGE[:TAG],具体可以登陆web查看

其次关闭SELinux 

[root@CentOS7 harbor]# docker tag nginx:latest 192.168.244.139/library/nginx:latest
[root@CentOS7 harbor]# docker push 192.168.244.139/library/nginx:latest
The push refers to repository [192.168.244.139/library/nginx]
a89b8f05da3a: Pushed
6eaad811af02: Pushed
b67d19e65ef6: Pushed
latest: digest: sha256:f56b43e9913cef097f246d65119df4eda1d61670f7f2ab720831a01f66f6ff9c size: 948

5.访问

http://192.168.244.139   ###默认账号admin,密码可以在harbor.yml文件内查看

参考链接:

https://docs.docker.com/compose/install/

https://github.com/goharbor/harbor/releases

https://github.com/goharbor/harbor/tree/master/docs/1.10


「 文章如果对你有帮助,请点个赞哦^^ 」 

0