12

程序员你是如何使用镜像中心Harbor的?

 3 years ago
source link: https://segmentfault.com/a/1190000038730795
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

iiQ322e.png!mobile

背景

harbor即docker的私服;管理公司内部输出的镜像制品;

是VMware公司中国团队为企业用户设计的镜像注册服务器,用途:存储和分发docker镜像;

在官方的docker registry服务中增加了安全,访问控制,审计,管理页面,发现,高可用等功能;

安装

找一台linux机器:提前安装好docker-compose;

  1. 下载harbor安装包

下载不下来可到csdn上找一个国内的资源下载;

wget https://github.com/goharbor/harbor/releases/download/v2.1.2/harbor-offline-installer-v2.1.2.tgz
  1. 解压
tar -xzvf harbor-offline-installer-v2.1.2.tgz
  1. 修改配置文件
vim harbor.cfg

修改:

harbor_admin_password; 默认密码

hostname:访问ip

  1. 启动harbor
./install.sh
  1. 查看容器
docker ps
  1. 启停harbor,通过docker-compose的方式进行
docker-compose stop
docker-compose start

harbor默认信任https协议,所以如果docker命令登录和推送镜像,需要添加 --insecure-registry到docker配置文件;

修改配置方法:

后台UI使用

打开: http://hostname/harbor

账号: admin

密码: 你预设的管理员密码

已经搭建好的harbor环境:

客户端使用

  1. docker登录注册中心
docker login  -u admin -password-stdin xxxx   xxx.com
  1. 本地docker镜像打tag:
docker tag repox:tagName xxx.com/project/repox:tagName
  1. 本地镜像推送:
docker push  xxx.com/myproject/myrepo:mytag
  1. 远程获取镜像并运行;

先登录,然后直接从镜像中心获取镜像即可;

见步骤1:

docker pull xxx.com/project/repox:tagName

实战

基于docker和docker-compose来运行本地开发好的程序;

  1. 本地作为ci的环境,制作镜像推送到harbor;
  2. 远程服务器作为CD的环境,通过harbor拉取镜像来运行程序;
  3. 扩展作为k8s的镜像仓库,支持k8s部署;

r6rmUvF.png!mobile

资料

源码: https://github.com/goharbor/harbor

官网: https://goharbor.io/

harbor安装和使用: https://www.toutiao.com/a6840826675383501320/

原创不易,关注诚可贵,转发价更高!转载请注明出处,让我们互通有无,共同进步,欢迎沟通交流。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK