存储Docker镜像至Harbor

avatar
作者
猴君
阅读量:0

提前安装好docker和docker compose

[root@docker compose]# docker version

[root@docker compose]# docker  compose version

下载harbor的压缩包

https://github.com/goharbor/harbor/releases/download/v2.10.3/harbor-offline-installer-v2.10.3.tgz

[root@docker compose]# mkdir /harbor
[root@docker compose]# cd /harbor

[root@docker harbor]# ls
harbor-offline-installer-v2.10.3.tgz

解压

[root@docker harbor]# tar xf harbor-offline-installer-v2.10.3.tgz 
[root@docker harbor]# ls
harbor  harbor-offline-installer-v2.10.3.tgz

[root@docker harbor]# cd harbor
[root@docker harbor]# ls
common.sh  harbor.v2.10.3.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare
[root@docker harbor]#

修改配置文件

[root@docker harbor]# cp harbor.yml.tmpl harbor.yml

[root@harbor harbor]# vim harbor.yml


hostname: 192.168.252.136   #修改

# http related config
http:
  # port for http, default is 80. If https enabled, this port will redirect to https port
  port: 80   #修改

#注释掉了https的配置
#其他的配置没有修改
# 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

执行安装脚本

[root@docker harbor]# ./install.sh 

[Step 0]: checking if docker is installed ...

Note: docker version: 26.1.4

[Step 1]: checking docker-compose is installed ...

Note: Docker Compose version v2.27.1

[Step 2]: loading Harbor images ...


Loaded image: goharbor/registry-photon:v2.10.3
Loaded image: goharbor/notary-server-photon:v2.10.3
Loaded image: goharbor/notary-signer-photon:v2.10.3
Loaded image: goharbor/harbor-log:v2.10.3
Loaded image: goharbor/redis-photon:v2.10.3
Loaded image: goharbor/harbor-jobservice:v2.10.3
Loaded image: goharbor/prepare:v2.10.3
Loaded image: goharbor/harbor-core:v2.10.3
Loaded image: goharbor/harbor-registryctl:v2.10.3
Loaded image: goharbor/nginx-photon:v2.10.3
Loaded image: goharbor/trivy-adapter-photon:v2.10.3
Loaded image: goharbor/harbor-portal:v2.10.3
Loaded image: goharbor/harbor-db:v2.10.3
Loaded image: goharbor/harbor-exporter:v2.10.3


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /harbor/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


Note: stopping existing Harbor instance ...


[Step 5]: starting Harbor ...
[+] Running 10/10
 ✔ Network harbor_harbor        Created                                                                                 0.1s 
 ✔ Container harbor-log         Started                                                                                 0.0s 
 ✔ Container redis              Started                                                                                 0.1s 
 ✔ Container harbor-db          Started                                                                                 0.1s 
 ✔ Container registryctl        Started                                                                                 0.1s 
 ✔ Container registry           Started                                                                                 0.1s 
 ✔ Container harbor-portal      Started                                                                                 0.1s 
 ✔ Container harbor-core        Started                                                                                 0.1s 
 ✔ Container harbor-jobservice  Started                                                                                 0.1s 
 ✔ Container nginx              Started                                                                                 0.1s 
✔ ----Harbor has been installed and started successfully.----
[root@docker harbor]# 

查看harbor相关容器运行情况

[root@docker harbor]# docker compose ps

windows机器上访问网站,并配置harbor

http://192.168.254.136/

默认的登录的用户名和密码
admin
Harbor12345

在harbor里创建一个项目 newProject
并且新建一个用户 user1  密码是Admin@123
授权 newProject 这个项目允许 user1 这个用户去访问,授予项目管理员权限

所有其他机器上配置这个仓库

[root@docker1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["https://ruk1gp3w.mirror.aliyuncs.com"],
  "insecure-registries" : ["192.168.254.136:80"]
}

重启docker守护进程配置文件以及docker

[root@docker1 ~]# systemctl daemon-reload
[root@docker1 ~]# systemctl restart docker

在原来安装harbor的宿主机上,重新启动harbor相关的容器

[root@docker harbor]# cd /harbor/harbor
[root@docker harbor]# docker compose up -d

[root@docker harbor]# docker compose restart

登录使用

user1用户,密码是Admin@123

[root@docker docker]# docker login  192.168.254.136:80
Username: user1
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@docker docker]# docker tag myapp:1.0 192.168.254.136:80/newProject/myapp:1.0
[root@docker docker]# docker push 192.168.254.136:80/newProject/myapp:1.0

其他机器上传镜像

root@docker:~/liu# docker tag 2ba278e9c4a1 192.168.254.136:80/newProject/myapp:1.1

root@docker:~/liu# docker push 192.168.254.136:80/newProject/myapp:1.1

其他机器拉取镜像

需要先登录harbor仓库

[root@nfs ~]# docker login  192.168.254.136:80
Username: user1
Password: 

[root@nfs ~]# docker pull  192.168.254.136:80/newProject/myapp:1.0

[root@nfs ~]# docker pull  192.168.254.136:80/newProject/myapp:1.1

    广告一刻

    为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!