docker仓库harbor安装与使用

docker最重要的三个概念:docker镜像,docker容器,以及docker仓库。docker镜像是是docker虚拟化中最基础的部分,通过docker镜像来启动一个docker容器,docker 容器是docker虚拟化的产物。

而docker仓库是用来存储docker镜像的地方,分为公有仓库和私用仓库。默认的公共仓库,对外开放、免费或者付费使用,企业测试环境和生产环境推荐自建私有仓库。私有仓库的特点:安全、可靠、稳定、高效,可以根据自身的业务体系进行灵活升级和管理。

使用harbor做为docker仓库的优点有:

安全,可靠,性能稳定。

一、部署harbo

#安装Docker-Compose
[root@localhost src]# yum install epel-release -y
[root@localhost src]# yum install python-pip -y
[root@localhost src]# pip install --upgrade pip
[root@localhost src]# curl -L https://github.com/docker/compose/releases/download/1.18.0/run.sh > /usr/local/bin/docker-compose 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   643  100   643    0     0   1267      0 --:--:-- --:--:-- --:--:--  1268

[root@localhost src]# chmod +x /usr/local/bin/docker-compose
[root@localhost src]# ls /usr/local/bin/docker-compose       
/usr/local/bin/docker-compose

#下载harbor 安装harbor
[root@localhost src]# cd /usr/src

[root@localhost src] wget -c https://storage.googleapis.com/harbor-releases/release-1.7.0/harbor-offline-installer-v1.7.0.tgz

[root@localhost src]# ls
debug  harbor  harbor-offline-installer-v1.7.0.tgz  kernels

[root@localhost src]# tar -zxvf harbor-offline-installer-v1.7.0.tgz
[root@localhost /]# cd /usr/src/harbor
[root@localhost harbor]# ./install.sh

 执行harbor安装脚本,会自动下载harbor与harbor相关docker镜像,配置,启动harbor容器

 

浏览器输入主机地址,即可打开harbor登录窗口

默认账号:admin 默认密码:Harbor12345,完成登录

 二、使用Harbor

1、创建私有仓库用户名,并且设置密码,

用户管理-创建用户

2、把创建用户绑定library仓库

项目-library-成员,添加刚才创建的用户

 

 docker login,确认使用创建用户登录

[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]# 

最后,通过push,把镜像上传到harbor仓库

[root@localhost src]# docker images
REPOSITORY                      TAG             IMAGE ID       CREATED         SIZE
nginx                           1.18.0          c2c45d506085   12 months ago   133MB
mysql                           5.7.32          cc8775c0fe94   15 months ago   449MB
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]#

例如,把上面nginx,mysql,php三个镜像上传到harbor仓库

上传之前,仓库内容为空,啥也没有

 首先,修改TAG,tag号修改为如下格式:

192.168.139.132/library/nginx:

192.168.139.132/library/mysql:

192.168.139.132/library/php:

[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]# 

PUSH上传镜像
 

[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仓库

如果要使用harbor仓库里面的镜像,只需要到登录到仓库,打开对应镜像,复制pull命令到linux里执行即可。


文章标签:

原文连接:https://blog.csdn.net/robin_cai/article/details/124292678

相关推荐

Linux一些错误总结

【Linux系统编程:基础IO 壹】简单复习C语言文件接口 | 学习系统文件接口 | 认识文件描述符 | Linux下,一切皆文件 | 重定向原理

logrotate command in Linux

FTP服务配置

CentOS7 离线安装 Zabbix5.0

Linux入门与进阶(二)

centos7基础操作

小白的Mac上手指南(干货)

最新京东短信登录+傻妞机器人保姆级部署教程(2022/7/20)

使用systemd,把服务装进 Linux 心脏里~

【Linux】Linux进程概念(学习复习兼顾)

Linux学习(2)——虚拟机和CentOS安装(图文详解超详细)

Linux学习(1) ——Linux基本介绍

Google 为造芯再掀“抢人大战”,英特尔 17 年老将加入

Linux 追踪技术 ftrace的使用(二)

Linux下玩转nginx系列(七)---nginx如何实现限流功能

Linux 是如何启动的

CD 从抓轨到搭建流媒体服务器 —— 以《月临寐乡》为例

shell查询prometheus数据

网络安全——信息隐藏-使用隐写术来防止敏感数据被盗用