2.Docker私有仓库Harbor安装
预安装环境处理
两台机器,一个安装仓库的机器vm01,一个客户机vm02
hostname 处理和hosts解析处理
[root@vm01 harbor]# cat /etc/hosts #两个机器均改
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.18 vm01.harbor.com
192.168.1.19 vm02.harbor.com
hostnamectl set-hostname vm01 #01机器执行
hostnamectl set-hostname vm02 #02机器执行
docker配置文件处理,两个机器都处理
[root@vm01 harbor]# cat /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {"max-size": "100m"},
"storage-driver": "overlay2",
"registry-mirrors":["https://xxxxx.mirror.aliyuncs.com"],
"insecure-registries":["192.168.1.18"]
}
重启docker
systemctl restart docker
docker-compose安装
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
安装harbor
https://github.com/goharbor/harbor/releases #下载地址,下载
tar zxvf harbor-offline-installer-v2.3.3.tgz
cd harbor #进入解压目录
docker load -i harbor.v2.3.3.tar.gz #导入解压文件中的镜像文件
修改harbor配置文件
cp harbor.yml.tmpl harbor.yml
vim harbor.yml #编辑该文件,以下为修改内容
hostname: vm01.harbor.com #修改hostname,以下几行注释掉
# 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
harbor_admin_password: Harbor12345 #密码改成你要的
........
#其他参数看自己所需要的去改
安装
[root@vm01 harbor]# ./prepare #安装检查
prepare base dir is set to /root/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[root@vm01 harbor]# ./install.sh #开始安装
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.9
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.21.2
[Step 2]: loading Harbor images ...
Loaded image: goharbor/harbor-portal:v2.3.3
Loaded image: goharbor/harbor-core:v2.3.3
Loaded image: goharbor/harbor-log:v2.3.3
Loaded image: goharbor/harbor-exporter:v2.3.3
Loaded image: goharbor/notary-server-photon:v2.3.3
Loaded image: goharbor/notary-signer-photon:v2.3.3
Loaded image: goharbor/chartmuseum-photon:v2.3.3
Loaded image: goharbor/harbor-db:v2.3.3
Loaded image: goharbor/harbor-registryctl:v2.3.3
Loaded image: goharbor/redis-photon:v2.3.3
Loaded image: goharbor/registry-photon:v2.3.3
Loaded image: goharbor/harbor-jobservice:v2.3.3
Loaded image: goharbor/nginx-photon:v2.3.3
Loaded image: goharbor/prepare:v2.3.3
Loaded image: goharbor/trivy-adapter-photon:v2.3.3
[Step 3]: preparing environment ...
[Step 4]: preparing harbor configs ...
prepare base dir is set to /root/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Clearing the configuration file: /config/portal/nginx.conf
Clearing the configuration file: /config/log/logrotate.conf
Clearing the configuration file: /config/log/rsyslog_docker.conf
Clearing the configuration file: /config/nginx/nginx.conf
Clearing the configuration file: /config/core/env
Clearing the configuration file: /config/core/app.conf
Clearing the configuration file: /config/registry/passwd
Clearing the configuration file: /config/registry/config.yml
Clearing the configuration file: /config/registryctl/env
Clearing the configuration file: /config/registryctl/config.yml
Clearing the configuration file: /config/db/env
Clearing the configuration file: /config/jobservice/env
Clearing the configuration file: /config/jobservice/config.yml
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
loaded secret from file: /data/secret/keys/secretkey
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating harbor-db ... done
Creating registry ... done
Creating registryctl ... done
Creating redis ... done
Creating harbor-portal ... done
Creating harbor-core ... done
Creating harbor-jobservice ... done
Creating nginx ... done
✔ ----Harbor has been installed and started successfully.----


新建项目

新建用户

给刚新建的项目locallib加用户BT

vm02登录后会生成认证配置文件
[root@localhost ~]# docker login 192.168.1.18
Username: BT
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 ~]# cat /root/.docker/config.json
{
"auths": {
"192.168.1.18": {
"auth": "QlQ6QUJDQGFiY0AxMjM="
}
}
}
上传镜像
[root@localhost ~]# docker tag debian:latest 192.168.1.18/locallib/debian:latest
[root@localhost ~]# docker push 192.168.1.18/locallib/debian:latest
The push refers to repository [192.168.1.18/locallib/debian]
5e6a409f30b6: Pushed
latest: digest: sha256:2c22645bfe97aa1ed1c930adf5970fee3454f9a42a19214051ec677cba805712 size: 529
检查镜像是否上传

关于harbor的高级应用
API接口编程,接口详细请查看仓库的API文档
http://192.168.1.18/devcenter-api-2.0
官方文档

浙公网安备 33010602011771号