返回总目录页

docker之企业级镜像仓库Harbor

Harbor概述

Habor是由VMWare公司开源的容器镜像仓库。事实上,Habor是在Docker Registry上进行了相应的
企业级扩展,从而获得了更加广泛的应用,这些新的企业级特性包括:管理用户界面,基于角色的访
问控制 ,AD/LDAP集成以及审计日志等,足以满足基本企业需求。
官方地址:https://vmware.github.io/harbor/cn/

Harbor部署

Harbor安装有3种方式:

• 在线安装:从Docker Hub下载Harbor相关镜像,因此安装软件包非常小
• 离线安装:安装包包含部署的相关镜像,因此安装包比较大
• OVA安装程序:当用户具有vCenter环境时,使用此安装程序,在部署OVA后启动Harbor

Harbor部署

包路径: 链接:https://pan.baidu.com/s/1QhCjEAoEepqELhm9IvMOTA 

有了harbor就不需要连外网下载镜像了。harbor一般部署在宿主机上。
我们将harbor的包上传到主机上,解压,配置。需要修改一下访问地址,我们这里配置成本机ip,修改一下密码,默认登录密码Harbor12345 。

[root@mcwk8s01 ~]# ls
anaconda-ks.cfg  harbor-offline-installer-v1.6.1.tgz  keepalived.conf  nginx.sh
[root@mcwk8s01 ~]# tar xf harbor-offline-installer-v1.6.1.tgz 
[root@mcwk8s01 ~]# ls
anaconda-ks.cfg  harbor  harbor-offline-installer-v1.6.1.tgz  keepalived.conf  nginx.sh
[root@mcwk8s01 ~]# cd harbor/
[root@mcwk8s01 harbor]# ls
common  docker-compose.chartmuseum.yml  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  ha  harbor.cfg  harbor.v1.6.1.tar.gz  install.sh  LICENSE  NOTICE  open_source_license  prepare
[root@mcwk8s01 harbor]# vim harbor.cfg 
[root@mcwk8s01 harbor]# egrep "10.0.0.31|Harbor12345" harbor.cfg 
hostname = 10.0.0.31
harbor_admin_password = Harbor12345
[root@mcwk8s01 harbor]# 

如果需要使用https那修改下配置:ui_url_protocol = http

它是使用docker compose来编排部署的。所以我们可以去去下载一个。安装方式如下链接参考

docker之docker-compose

 因为harbor自己要起nginx,会占用80服务,我们主机1上有nginx。那么我们换到主机5上面去把=吧

[root@mcwk8s01 harbor]# scp /usr/local/bin/docker-compose 10.0.0.35:/usr/local/bin/
root@10.0.0.35's password: 
docker-compose                                                                                                                                                                 100%   10MB  23.5MB/s   00:00    
[root@mcwk8s01 harbor]# ls
common  docker-compose.chartmuseum.yml  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  ha  harbor.cfg  harbor.v1.6.1.tar.gz  install.sh  LICENSE  NOTICE  open_source_license  prepare
[root@mcwk8s01 harbor]# cd ..
[root@mcwk8s01 ~]# ls
anaconda-ks.cfg  harbor  harbor-offline-installer-v1.6.1.tgz  keepalived.conf  nginx.sh
[root@mcwk8s01 ~]# scp -rp harbor 10.0.0.35:/root/
root@10.0.0.35's password: 
nginx.https.conf                                                                                                                                                               100% 3045     3.7MB/s   00:00    
notary.server.conf 

./prepare

[root@mcwk8s05 harbor]# ls
common  docker-compose.chartmuseum.yml  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  ha  harbor.cfg  harbor.v1.6.1.tar.gz  install.sh  LICENSE  NOTICE  open_source_license  prepare
[root@mcwk8s05 harbor]# ./prepare 
Generated and saved secret to file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/registryctl/env
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.
[root@mcwk8s05 harbor]#

./install.sh

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

[Step 0]: checking installation environment ...

Note: docker version: 20.10.21

Note: docker-compose version: 1.21.0

[Step 1]: loading Harbor images ...
ad50e89f4922: Loading layer [==================================================>]  133.4MB/133.4MB
8c9a00a7f290: Loading layer [==================================================>]  73.29MB/73.29MB
078e22641f73: Loading layer [==================================================>]  3.584kB/3.584kB
5494f0d704cb: Loading layer [==================================================>]  3.072kB/3.072kB
34c7e304d18b: Loading layer [==================================================>]  4.096kB/4.096kB
ae9209f78c11: Loading layer [==================================================>]  3.584kB/3.584kB
1498359f7391: Loading layer [==================================================>]  9.728kB/9.728kB
Loaded image: goharbor/harbor-log:v1.6.1
bb738fd5b202: Loading layer [==================================================>]  23.38MB/23.38MB
51f6c7e046ae: Loading layer [==================================================>]  21.15MB/21.15MB
67ff79ae8340: Loading layer [==================================================>]  21.15MB/21.15MB
Loaded image: goharbor/harbor-jobservice:v1.6.1
b5be864bae6a: Loading layer [==================================================>]  83.89MB/83.89MB
9fdbae37c606: Loading layer [==================================================>]  3.072kB/3.072kB
c24b06c70085: Loading layer [==================================================>]   59.9kB/59.9kB
946c040a69da: Loading layer [==================================================>]  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v1.6.1
747ac74b0475: Loading layer [==================================================>]  5.128MB/5.128MB
Loaded image: goharbor/nginx-photon:v1.6.1
3d4aae33f4f1: Loading layer [==================================================>]    683MB/683MB
3cb271cda7e0: Loading layer [==================================================>]   7.68kB/7.68kB
7ae402931bdb: Loading layer [==================================================>]  197.6kB/197.6kB
Loaded image: goharbor/harbor-migrator:v1.6.1
67747a74e108: Loading layer [==================================================>]  158.1MB/158.1MB
93f3d22257c7: Loading layer [==================================================>]  35.08MB/35.08MB
2eda636f347b: Loading layer [==================================================>]   2.56kB/2.56kB
7a3b4ef015e8: Loading layer [==================================================>]  35.08MB/35.08MB
Loaded image: goharbor/chartmuseum-photon:v0.7.1-v1.6.1
038c23438769: Loading layer [==================================================>]  23.38MB/23.38MB
a6a0201bf457: Loading layer [==================================================>]  26.88MB/26.88MB
aa0986b7d608: Loading layer [==================================================>]  7.168kB/7.168kB
830a350d7059: Loading layer [==================================================>]  11.32MB/11.32MB
3100afecce3d: Loading layer [==================================================>]  26.87MB/26.87MB
Loaded image: goharbor/harbor-ui:v1.6.1
15134eb6d277: Loading layer [==================================================>]  95.85MB/95.85MB
02cff5f31ca4: Loading layer [==================================================>]  6.656kB/6.656kB
3e43f3cb1d4c: Loading layer [==================================================>]  2.048kB/2.048kB
4ab1b74a5650: Loading layer [==================================================>]   7.68kB/7.68kB
9c78faccbd48: Loading layer [==================================================>]   2.56kB/2.56kB
158d4a16071f: Loading layer [==================================================>]   2.56kB/2.56kB
6a2fbfb6100b: Loading layer [==================================================>]   2.56kB/2.56kB
Loaded image: goharbor/harbor-db:v1.6.1
b15fe66f326a: Loading layer [==================================================>]  23.38MB/23.38MB
336e69120569: Loading layer [==================================================>]  3.072kB/3.072kB
f308142e2037: Loading layer [==================================================>]  3.072kB/3.072kB
3119c7884a49: Loading layer [==================================================>]  2.048kB/2.048kB
fafa9955d095: Loading layer [==================================================>]   22.8MB/22.8MB
4c53b946082a: Loading layer [==================================================>]   22.8MB/22.8MB
Loaded image: goharbor/registry-photon:v2.6.2-v1.6.1
0fee5e457010: Loading layer [==================================================>]  23.38MB/23.38MB
6d1b402441fc: Loading layer [==================================================>]  12.16MB/12.16MB
765a288fcf5a: Loading layer [==================================================>]   17.3MB/17.3MB
da4578643aee: Loading layer [==================================================>]  11.26kB/11.26kB
f02d275fa76f: Loading layer [==================================================>]  3.072kB/3.072kB
4a3d1e973223: Loading layer [==================================================>]  29.46MB/29.46MB
Loaded image: goharbor/notary-server-photon:v0.5.1-v1.6.1
918b224a19fd: Loading layer [==================================================>]  10.95MB/10.95MB
ff41acdef199: Loading layer [==================================================>]   17.3MB/17.3MB
4389d5e9282a: Loading layer [==================================================>]  11.26kB/11.26kB
8a0e0bb6ed63: Loading layer [==================================================>]  3.072kB/3.072kB
d437ffa494e0: Loading layer [==================================================>]  28.24MB/28.24MB
Loaded image: goharbor/notary-signer-photon:v0.5.1-v1.6.1
1c86e9f19207: Loading layer [==================================================>]  158.1MB/158.1MB
3b4698fe61a0: Loading layer [==================================================>]  10.93MB/10.93MB
8dbd6d55a6cd: Loading layer [==================================================>]  2.048kB/2.048kB
5cb748f1dcf1: Loading layer [==================================================>]  48.13kB/48.13kB
f86a42ee549b: Loading layer [==================================================>]  10.98MB/10.98MB
Loaded image: goharbor/clair-photon:v2.0.6-v1.6.1
18abf81cd9fd: Loading layer [==================================================>]  23.38MB/23.38MB
66a3e670c5b5: Loading layer [==================================================>]  15.58MB/15.58MB
9cdd51a1e20c: Loading layer [==================================================>]  15.36kB/15.36kB
9aedba3496f1: Loading layer [==================================================>]  15.58MB/15.58MB
Loaded image: goharbor/harbor-adminserver:v1.6.1


[Step 2]: preparing environment ...
Clearing the configuration file: ./common/config/adminserver/env
Clearing the configuration file: ./common/config/ui/env
Clearing the configuration file: ./common/config/ui/app.conf
Clearing the configuration file: ./common/config/ui/private_key.pem
Clearing the configuration file: ./common/config/db/env
Clearing the configuration file: ./common/config/jobservice/env
Clearing the configuration file: ./common/config/jobservice/config.yml
Clearing the configuration file: ./common/config/registry/config.yml
Clearing the configuration file: ./common/config/registry/root.crt
Clearing the configuration file: ./common/config/registryctl/env
Clearing the configuration file: ./common/config/registryctl/config.yml
Clearing the configuration file: ./common/config/nginx/nginx.conf
Clearing the configuration file: ./common/config/log/logrotate.conf
loaded secret from file: /data/secretkey
Generated configuration file: ./common/config/nginx/nginx.conf
Generated configuration file: ./common/config/adminserver/env
Generated configuration file: ./common/config/ui/env
Generated configuration file: ./common/config/registry/config.yml
Generated configuration file: ./common/config/db/env
Generated configuration file: ./common/config/jobservice/env
Generated configuration file: ./common/config/jobservice/config.yml
Generated configuration file: ./common/config/log/logrotate.conf
Generated configuration file: ./common/config/registryctl/env
Generated configuration file: ./common/config/ui/app.conf
Generated certificate, key file: ./common/config/ui/private_key.pem, cert file: ./common/config/registry/root.crt
The configuration files are ready, please use docker-compose to start the service.


[Step 3]: checking existing instance of Harbor ...


[Step 4]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
Creating harbor-log ... done
Creating redis              ... done
Creating registry           ... done
Creating harbor-adminserver ... done
Creating harbor-db          ... done
Creating harbor-ui          ... done
Creating nginx              ... done
Creating harbor-jobservice  ... done

✔ ----Harbor has been installed and started successfully.----

Now you should be able to visit the admin portal at http://10.0.0.31. 
For more details, please visit https://github.com/goharbor/harbor .

[root@mcwk8s05 harbor]# 

查看导入的镜像

[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# docker images
REPOSITORY                                                        TAG             IMAGE ID       CREATED       SIZE
busybox                                                           latest          bc01a3326866   11 days ago   1.24MB
nginx                                                             latest          76c69feac34e   12 days ago   142MB
nginx                                                             1.14            295c7be07902   3 years ago   109MB
nginx                                                             1.14.2          295c7be07902   3 years ago   109MB
goharbor/chartmuseum-photon                                       v0.7.1-v1.6.1   f0a2dbee1ff1   4 years ago   350MB
goharbor/harbor-migrator                                          v1.6.1          60e8be845b35   4 years ago   798MB
goharbor/redis-photon                                             v1.6.1          6a67380bb061   4 years ago   210MB
goharbor/clair-photon                                             v2.0.6-v1.6.1   c4fcdbae7df2   4 years ago   302MB
goharbor/notary-server-photon                                     v0.5.1-v1.6.1   f1afd44d9f9b   4 years ago   209MB
goharbor/notary-signer-photon                                     v0.5.1-v1.6.1   83aa51867207   4 years ago   207MB
goharbor/registry-photon                                          v2.6.2-v1.6.1   f4cb5e83f0a4   4 years ago   196MB
goharbor/nginx-photon                                             v1.6.1          9ca888fe33b2   4 years ago   132MB
goharbor/harbor-log                                               v1.6.1          9b1ea3f29465   4 years ago   198MB
goharbor/harbor-jobservice                                        v1.6.1          9ca6fd371ca6   4 years ago   192MB
goharbor/harbor-ui                                                v1.6.1          305ee5b8952c   4 years ago   215MB
goharbor/harbor-adminserver                                       v1.6.1          a3e95f74984e   4 years ago   181MB
goharbor/harbor-db                                                v1.6.1          3bea3bff0190   4 years ago   219MB
siriuszg/kubernetes-dashboard-amd64                               v1.8.3          784cf2722f44   4 years ago   102MB
registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64   3.0             99e59f495ffa   6 years ago   747kB
[root@mcwk8s05 harbor]# 

运行服务和查看状态:

docker-compose up -d   #应该是需要在服务的目录下进行,好像是会读取docker-compose.yml文件去部署

docker-compose ps

[root@mcwk8s05 harbor]# ls
common  docker-compose.chartmuseum.yml  docker-compose.clair.yml  docker-compose.notary.yml  docker-compose.yml  ha  harbor.cfg  harbor.v1.6.1.tar.gz  install.sh  LICENSE  NOTICE  open_source_license  prepare
[root@mcwk8s05 harbor]# docker-compose up -d
harbor-log is up-to-date
redis is up-to-date
registry is up-to-date
harbor-db is up-to-date
harbor-adminserver is up-to-date
harbor-ui is up-to-date
harbor-jobservice is up-to-date
nginx is up-to-date
[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# docker-compose ps
       Name                     Command                  State                                                            Ports                                                      
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver   /harbor/start.sh                 Up (healthy)                                                                                                                   
harbor-db            /entrypoint.sh postgres          Up (healthy)   5432/tcp                                                                                                        
harbor-jobservice    /harbor/start.sh                 Up                                                                                                                             
harbor-log           /bin/sh -c /usr/local/bin/ ...   Up (healthy)   127.0.0.1:1514->10514/tcp                                                                                       
harbor-ui            /harbor/start.sh                 Up (healthy)                                                                                                                   
nginx                nginx -g daemon off;             Up (healthy)   0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:4443->4443/tcp,:::4443->4443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp
redis                docker-entrypoint.sh redis ...   Up             6379/tcp                                                                                                        
registry             /entrypoint.sh /etc/regist ...   Up (healthy)   5000/tcp                                                                                                        
[root@mcwk8s05 harbor]# 

访问地址:http://10.0.0.35/

如下,进入了登录页面了

 

 默认用户  admin   

默认用户密码 Harbor12345

登录之后默认有个仓库,是个公共的仓库,我们可以往里面上传镜像。我们主要用的项目和用户。

harbor的基本使用

 harbor页面的基本使用

 创建用户

ASdf556433377*&&

 

 

 为项目添加成员(管理员)

 

 

 推送镜像的参考命令

这个配置的地址有问题,我们之前在31上配置的。传到35上了,但是没有修改配置,配置那么多。我们重新部署一下吧

 停止服务

[root@mcwk8s05 harbor]# docker-compose stop
Stopping harbor-jobservice  ... done
Stopping nginx              ... done
Stopping harbor-ui          ... done
Stopping harbor-adminserver ... done
Stopping harbor-db          ... done
Stopping registry           ... done
Stopping redis              ... done
Stopping harbor-log         ... done
[root@mcwk8s05 harbor]# 

重新部署之后就对了。我是将harbor目录删除了,重新上传的,但是刚刚创建的成员machangwei还在的,看来数据库或者是存储的数据是在别处,没有受到影响吗。

 

 推送镜像到harbor

推送总结

1、配置http镜像仓库可信任
# vi /etc/docker/daemon.json
{"insecure-registries":["reg.ctnrs.com"]}
# systemctl restart docker
2、打标签
# docker tag centos:6 reg.ctnrs.com/library/centos:6
3、上传
# docker push reg.ctnrs.com/library/centos:6
4、下载
# docker pull reg.ctnrs.com/library/centos:6

推送案例

如推荐的推送案例,我们需要打上标签,标签地址是我们的项目访问地址,然后push这个有仓库地址标签的镜像

 打个标签

[root@mcwk8s05 harbor]# docker images tomcat
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
tomcat       latest    3500a757f51d   3 days ago   473MB
[root@mcwk8s05 harbor]# docker tag tomcat 10.0.0.35/library/tomcat:v1
[root@mcwk8s05 harbor]# docker images tomcat
REPOSITORY   TAG       IMAGE ID       CREATED      SIZE
tomcat       latest    3500a757f51d   3 days ago   473MB
[root@mcwk8s05 harbor]# docker images 10.0.0.35/library/tomcat:v1
REPOSITORY                 TAG       IMAGE ID       CREATED      SIZE
10.0.0.35/library/tomcat   v1        3500a757f51d   3 days ago   473MB
[root@mcwk8s05 harbor]# 

我们推送镜像需要登录仓库。docker默认是以https方式访问镜像仓库的。我们这里仓库是使用的http的,那么需要在docker配置文件里加上可信任

# vi /etc/docker/daemon.json
{"insecure-registries":["reg.ctnrs.com"]}
需要重启服务
[root@mcwk8s05 harbor]# ip a|grep 10.0.0.35
    inet 10.0.0.35/24 brd 10.0.0.255 scope global eth0
[root@mcwk8s05 harbor]# cat /etc/docker/daemon.json 
{"registry-mirrors":["https://reg-mirror.qiniu.com/","https://docker.mirrors.ustc.edu.cn/","https://hub-mirror.c.163.com/"],
"insecure-registries":["10.0.0.35"]
}
[root@mcwk8s05 harbor]# systemctl restart docker
[root@mcwk8s05 harbor]# docker-compose ps
       Name                     Command                       State                                                                Ports                                                      
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver   /harbor/start.sh                 Exit 137                                                                                                                                
harbor-db            /entrypoint.sh postgres          Up (healthy)            5432/tcp                                                                                                        
harbor-jobservice    /harbor/start.sh                 Up                                                                                                                                      
harbor-log           /bin/sh -c /usr/local/bin/ ...   Up (healthy)            127.0.0.1:1514->10514/tcp                                                                                       
harbor-ui            /harbor/start.sh                 Up (health: starting)                                                                                                                   
nginx                nginx -g daemon off;             Up (health: starting)   0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:4443->4443/tcp,:::4443->4443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp
redis                docker-entrypoint.sh redis ...   Exit 128                                                                                                                                
registry             /entrypoint.sh /etc/regist ...   Up (healthy)            5000/tcp                                                                                                        
[root@mcwk8s05 harbor]# docker-compose up -d
harbor-log is up-to-date
Starting redis ... 
Starting harbor-adminserver ... 
Starting redis              ... done
Starting harbor-adminserver ... done
harbor-ui is up-to-date
nginx is up-to-date
harbor-jobservice is up-to-date
[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# docker-compose ps
       Name                     Command                       State                                                                Ports                                                      
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
harbor-adminserver   /harbor/start.sh                 Up (health: starting)                                                                                                                   
harbor-db            /entrypoint.sh postgres          Up (healthy)            5432/tcp                                                                                                        
harbor-jobservice    /harbor/start.sh                 Up                                                                                                                                      
harbor-log           /bin/sh -c /usr/local/bin/ ...   Up (healthy)            127.0.0.1:1514->10514/tcp                                                                                       
harbor-ui            /harbor/start.sh                 Up (health: starting)                                                                                                                   
nginx                nginx -g daemon off;             Up (health: starting)   0.0.0.0:443->443/tcp,:::443->443/tcp, 0.0.0.0:4443->4443/tcp,:::4443->4443/tcp, 0.0.0.0:80->80/tcp,:::80->80/tcp
redis                docker-entrypoint.sh redis ...   Up                      6379/tcp                                                                                                        
registry             /entrypoint.sh /etc/regist ...   Up (healthy)            5000/tcp                                                                                                        
[root@mcwk8s05 harbor]# 

登录仓库并i推送镜像到仓库

[root@mcwk8s05 harbor]# docker login 10.0.0.35
Username: machangwei
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@mcwk8s05 harbor]# docker push 10.0.0.35/library/tomcat:v1
The push refers to repository [10.0.0.35/library/tomcat]
dac98e58cc38: Pushed 
052fe235dec6: Pushed 
8129280902f4: Pushed 
9e5fabf427d2: Pushed 
6657f9faac5f: Pushed 
3a87162a073c: Pushed 
f4a670ac65b6: Pushed 
v1: digest: sha256:8aaa923ea3dbd010cf77faf9e9ad0624fe19fcb5a3dae4cb34c235a3150c00cc size: 1788
[root@mcwk8s05 harbor]# 

查看harbor仓库上,已经有了刚刚上传的镜像

 点击进入,看到推送的信息

 我们再把nginx推送上去,把tomcat再推送第二个版本上去。需要注意的是,我们推送前一定要打上我们自己仓库的地址的镜像标签,推送这个有标签的镜像,别直接推送未打标签的,省的推送到别人的仓库了。

[root@mcwk8s05 harbor]# docker images nginx:1.14
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
nginx        1.14      295c7be07902   3 years ago   109MB
[root@mcwk8s05 harbor]# docker images 10.0.0.35/library/tomcat:v1
REPOSITORY                 TAG       IMAGE ID       CREATED      SIZE
10.0.0.35/library/tomcat   v1        3500a757f51d   3 days ago   473MB
[root@mcwk8s05 harbor]# docker tag 10.0.0.35/library/tomcat:v1   10.0.0.35/library/tomcat:v2
[root@mcwk8s05 harbor]# docker images 10.0.0.35/library/tomcat:v2
REPOSITORY                 TAG       IMAGE ID       CREATED      SIZE
10.0.0.35/library/tomcat   v2        3500a757f51d   3 days ago   473MB
[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# docker push nginx:1.14
The push refers to repository [docker.io/library/nginx]
82ae01d5004e: Layer already exists 
b8f18c3b860b: Preparing 
5dacd731af1b: Preparing 
^C
[root@mcwk8s05 harbor]# docker tag nginx:1.14  10.0.0.35/library/nginx:1.14
[root@mcwk8s05 harbor]# docker images 10.0.0.35/library/nginx:1.14
REPOSITORY                TAG       IMAGE ID       CREATED       SIZE
10.0.0.35/library/nginx   1.14      295c7be07902   3 years ago   109MB
[root@mcwk8s05 harbor]# 
[root@mcwk8s05 harbor]# docker push 10.0.0.35/library/nginx
Using default tag: latest
The push refers to repository [10.0.0.35/library/nginx]
tag does not exist: 10.0.0.35/library/nginx:latest
[root@mcwk8s05 harbor]# docker push 10.0.0.35/library/nginx:1.14
The push refers to repository [10.0.0.35/library/nginx]
82ae01d5004e: Pushed 
b8f18c3b860b: Pushed 
5dacd731af1b: Pushed 
1.14: digest: sha256:706446e9c6667c0880d5da3f39c09a6c7d2114f5a5d6b74a2fafd24ae30d2078 size: 948
[root@mcwk8s05 harbor]# docker push 10.0.0.35/library/tomcat:v2
The push refers to repository [10.0.0.35/library/tomcat]
dac98e58cc38: Layer already exists 
052fe235dec6: Layer already exists 
8129280902f4: Layer already exists 
9e5fabf427d2: Layer already exists 
6657f9faac5f: Layer already exists 
3a87162a073c: Layer already exists 
f4a670ac65b6: Layer already exists 
v2: digest: sha256:8aaa923ea3dbd010cf77faf9e9ad0624fe19fcb5a3dae4cb34c235a3150c00cc size: 1788
[root@mcwk8s05 harbor]# 

我们再看下,这个仓库中的tomcat有两个版本了

 

 仓库中有两个镜像

 我们想要下载指定镜像指定版本的话可以在这里看下载地址,复制命令

 

 比如上面我们复制的是    docker pull 10.0.0.35/library/tomcat:v1

我们在另一台主机,主机6上下载一下。我们下载的主机,由于harbor是http方式的,我们也需要添加配置,让harbor主机是受信任的

[root@mcwk8s06 ~]# docker pull 10.0.0.35/library/tomcat:v1
Error response from daemon: Get "https://10.0.0.35/v2/": dial tcp 10.0.0.35:443: connect: connection refused
[root@mcwk8s06 ~]# vim /etc/docker/daemon.json 
[root@mcwk8s06 ~]# cat /etc/docker/daemon.json
{"registry-mirrors":["https://reg-mirror.qiniu.com/","https://docker.mirrors.ustc.edu.cn/","https://hub-mirror.c.163.com/"],
"insecure-registries":["10.0.0.35"]
}
[root@mcwk8s06 ~]# systemctl restart docker
[root@mcwk8s06 ~]# 
[root@mcwk8s06 ~]# docker pull 10.0.0.35/library/tomcat:v1
v1: Pulling from library/tomcat
e96e057aae67: Pull complete 
014fa72e018d: Pull complete 
3c9b94dcf278: Pull complete 
4624f8447672: Pull complete 
fbaf4e13e099: Pull complete 
fe482f3df622: Pull complete 
9c389ce12d0e: Pull complete 
Digest: sha256:8aaa923ea3dbd010cf77faf9e9ad0624fe19fcb5a3dae4cb34c235a3150c00cc
Status: Downloaded newer image for 10.0.0.35/library/tomcat:v1
10.0.0.35/library/tomcat:v1
[root@mcwk8s06 ~]# docker images 10.0.0.35/library/tomcat:v1
REPOSITORY                 TAG       IMAGE ID       CREATED      SIZE
10.0.0.35/library/tomcat   v1        3500a757f51d   3 days ago   473MB
[root@mcwk8s06 ~]# 

 

 

 

 

 

 

 

 

 

 

 

 

 

posted @ 2022-11-06 22:36  马昌伟  阅读(1001)  评论(0编辑  收藏  举报
博主链接地址:https://www.cnblogs.com/machangwei-8/