Docker镜像管理之Harbor
github: https://github.com/goharbor/harbor
官网:https://goharbor.io/docs/2.5.0/
[安装]
1. 查看是否达到安装条件
2.根据实际情况选择 在线版本和离线版本
-
Online installer: The online installer downloads the Harbor images from Docker hub. For this reason, the installer is very small in size.
-
Offline installer: Use the offline installer if the host to which are deploying Harbor does not have a connection to the Internet. The offline installer contains pre-built images, so it is larger than the online installer.
我这里使用的在线版本进行安装:
3.下载并安装
wget https://github.com/goharbor/harbor/releases/download/v2.5.0/harbor-online-installer-v2.5.0.tgz tar -zxvf harbor-online-installer-v2.5.0.tgz
修改配置文件:
mv harbor.yml.tmpl harbor.yml
vim harbor.yml
如果配置的域名或使用指定的端口的话, 需要修改 hostname:
如果80端口有占用的话, 需要修改参数: port
如果没有使用https的话, 需要将参数进行注释: https 部分
extenal_url: 可以与hostname 保持一致
注意点: 可以修改这里的admin登录的密码 harbor_admin_password
安装:
./install.sh
打开web界面 进行登录
1)创建项目(共有,私有)
2)用户管理 > 创建用户
3)将用户绑定到指定的仓库下
使用:
1) 登录
docker login -u xxx -p xxx xx.xxx.com 例如: [root@localhost src]# docker login 192.168.139.132 Username: caixin 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 src]#
2)镜像推送
先进行打tag [root@localhost src]# docker tag nginx:1.18.0 192.168.139.132/library/nginx:1.18.0 [root@localhost src]# docker tag mysql:5.7.32 192.168.139.132/library/mysql:5.7.32 [root@localhost src]# docker tag php:5.6-fpm 192.168.139.132/library/php:5.6-fpm [root@localhost src]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.139.132/library/nginx 1.18.0 c2c45d506085 12 months ago 133MB nginx 1.18.0 c2c45d506085 12 months ago 133MB 192.168.139.132/library/mysql 5.7.32 cc8775c0fe94 15 months ago 449MB mysql 5.7.32 cc8775c0fe94 15 months ago 449MB 192.168.139.132/library/php 5.6-fpm 3458979c7744 3 years ago 344MB php 5.6-fpm 3458979c7744 3 years ago 344MB goharbor/chartmuseum-photon v0.7.1-v1.7.0 666d74cc236a 3 years ago 111MB goharbor/harbor-migrator v1.7.0 482699d98927 3 years ago 799MB goharbor/redis-photon v1.7.0 8adff755797f 3 years ago 96.1MB goharbor/clair-photon v2.0.7-v1.7.0 7e72f6ba05bd 3 years ago 165MB goharbor/notary-server-photon v0.6.1-v1.7.0 b4a22960dfce 3 years ago 102MB goharbor/notary-signer-photon v0.6.1-v1.7.0 bb0db7ebd1de 3 years ago 99.6MB goharbor/harbor-registryctl v1.7.0 1906a8b84fa5 3 years ago 101MB goharbor/registry-photon v2.6.2-v1.7.0 677f21b09362 3 years ago 86.4MB goharbor/nginx-photon v1.7.0 6ed96fc73f83 3 years ago 35.5MB goharbor/harbor-log v1.7.0 722fa4a77846 3 years ago 81MB goharbor/harbor-jobservice v1.7.0 effd390c0cd4 3 years ago 83.8MB goharbor/harbor-core v1.7.0 2ebd58ce5638 3 years ago 95.2MB goharbor/harbor-portal v1.7.0 72a291f86bab 3 years ago 40.2MB goharbor/harbor-adminserver v1.7.0 9f850341a571 3 years ago 72MB goharbor/harbor-db v1.7.0 45d94fe5fee5 3 years ago 133MB docker/compose 1.18.0 8a01ec091f90 4 years ago 19.2MB [root@localhost src]#
3)推送
[root@localhost src]# docker push 192.168.139.132/library/nginx:1.18.0 [root@localhost src]# docker push 192.168.139.132/library/mysql:5.7.32 The push refers to repository [192.168.139.132/library/mysql] df1ee06a30c4: Pushed 902dedce4cb4: Pushed 569a2d6e5302: Pushed 8bdb6ee41f57: Pushed 98d98806c8ac: Pushed 0394a41efa73: Pushed c484a3b6d841: Pushed 6d23902c2a54: Pushed 74c86dffd46f: Pushed ef4a33cee7a0: Pushed cb42413394c4: Pushed 5.7.32: digest: sha256:860f4bcc18607de9f40a7453c7dc160313ecc3a5a46be3b060569b6216d348f6 size: 2621 [root@localhost src]# [root@localhost src]# docker push 192.168.139.132/library/php:5.6-fpm The push refers to repository [192.168.139.132/library/php] bf97b47da88d: Pushed 56d6009fbc8b: Pushed b6d5993da6a4: Pushed c9e57440aae2: Pushed 5e2afcdec12b: Pushed 6e4f2e72b0d9: Pushed 6eb3cfd4ad9e: Pushed 82bded2c3a7c: Pushed b87a266e6a9c: Pushed 3c816b4ead84: Pushed 5.6-fpm: digest: sha256:7cfd6ccb875ff314b2c672b62aa3169fe79d54bf3422b7b0017955b3457ca1a7 size: 2410 [root@localhost src]#
就可以在harbor中查看到推送上去的镜像了
# 登录 docker login http://harbor.xxx.com # 打标签 docker tag hello:v1 harbor.xxx.com/library/docker-hello:v1.0.0 # 推送镜像 docker push harbor.xxx.com/library/docker-hello:v1.0.0 # 推送镜像 docker pull harbor.xxx.com/library/docker-hello:v1.0.0
如果出现无法登录的错误, 需要配置仓库地址, 在配置文件中添加/etc/docker/daemon.json
{ ... "insecure-registries": ["http://harbor.xxx.com"] } 重启生效 systemctl daemon-reload systemctl restart docker
镜像一般较大,需要设置nginx的最大文件上限
vim /usr/local/nginx/conf/nginx.conf
http {
...
client_max_body_size 1024m;
}