docker私有仓库搭建(腾讯云、registry、harbor三种私有仓库搭建)

**

一、腾讯云容器镜像服务个人版

**
步骤1:注册腾讯云账号
步骤2:开通容器镜像服务

在 腾讯云控制台 中,选择云产品 > 容器镜像服务,进入容器镜像服务控制台,
步骤3:初始化个人版服务
登录 容器镜像服务控制台,进入“实例管理”页面。

步骤4:创建命名空间
选择左侧导航栏中的命名空间,进入“命名空间”列表页面,选择个人版实例,单击新建。
说明:
命名空间用于管理实例内的镜像仓库,不直接存储容器镜像,可映射为企业内团队、项目或是其他自定义层级。
在弹出的“新建命名空间”窗口中,参考以下提示配置命名空间信息并单击确定。如下图所示:

名称:建议使用企业内团队或项目进行命名,个人版实例为共享实例,命名空间名称全局不可重复,即无法新建其他用户已经占用的命名空间名称。

步骤5:创建镜像仓库(可选)
说明:
您可在完成命名空间创建后,直接通过 Docker 客户端向该命名空间内推送镜像,对应的镜像仓库将被自动创建。

单击左侧导航栏中的镜像仓库,进入“镜像仓库”列表页面,在顶部选择个人版实例。
在这里插入图片描述
步骤6:镜像操作
登录腾讯云docker registry


sudo docker login --username=100013162698  ccr.ccs.tencentyun.com

从registry拉取镜像

sudo docker pull ccr.ccs.tencentyun.com/docker_nss/nginx_mysql_php:[tag]

将镜像推送到registry

sudo docker tag [ImageId] ccr.ccs.tencentyun.com/docker_nss/nginx_mysql_php:[tag]
sudo docker push ccr.ccs.tencentyun.com/docker_nss/nginx_mysql_php:[tag]

其中[ImageId]请根据您的实际镜像ID信息进行填写, [tag]请根据您的镜像版本信息进行填写。


二、私有registry 的搭建

参考:https://cloud.tencent.com/developer/article/1437186
步骤1:拉去registry镜像

docker pull registry

步骤2:运行私有库registry,相当于本地有个私有docker hub

docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --name myregistry registry

Registry服务默认会将上传的镜像保存在容器的/var/lib/registry,我们将主机的/opt/registry目录挂载到该目录,即可实现将镜像保存到主机的/opt/registry目录了

步骤3:推送

docker tag nginx:latest localhost:5000/nginx:latest
docker push localhost:5000/nginx:latest

步骤3:拉取镜像

docker pull localhost:5000/镜像名:版本号

三、harbor 的搭建

docker 官方提供的私有仓库 registry,用起来虽然简单 ,但在管理的功能上存在不足。 Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,harbor使用的是官方的docker registry(v2命名是distribution)服务去完成。harbor在docker distribution的基础上增加了一些安全、访问控制、管理的功能以满足企业对于镜像仓库的需求。

1.搭建
下载:下载地址:https://github.com/goharbor/harbor/releases 本文是有 v2.4.2rc1

解压:

tar -xvf harbor-offline-installer-v2.4.2-rc1.tgz

修改 harbor.cfg

# cp harbor.yml.tmpl  harbor.yml
# mkdir -p /opt/application/harbor     //用于存放harbor的持久化数据
harbor.yml配置文件主要修改参数如下:
hostname: 192.168.0.8:9999          //设置访问地址,可以使用ip、域名,不可以设置为127.0.0.1或localhost。默认情况下,harbor使用的端口是80,若使用自定义的端口,除了要改docker-compose.yml文件中的配置外,这里的hostname也要加上自定义的端口,否则在docker login、push时会报错
#http配置
http:
# port for http, default is 80. If https enabled, this port will redirect to https port
port: 9999                      

#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

#external_url: https://reg.mydomain.com:8433      //如果要启用外部代理,比如外层的NGINX、LB等,请取消注释external_url,当它启用时,hostname将不再使用。

harbor_admin_password: Harbor12345         //admin密码

 

#数据库配置
database:
# The password for the root user of Harbor DB. Change this before any production use.
password: root123
# The maximum number of connections in the idle connection pool. If it <=0, no idle connections are retained.
max_idle_conns: 50
# The maximum number of open connections to the database. If it <= 0, then there is no limit on the number of open connections.
# Note: the default number of connections is 100 for postgres.
max_open_conns: 100


#持久化数据目录

data_volume: /opt/application/harbor

……

通过运行 install.sh 构建镜像,并把服务启动起来:

./install.sh

2. 使用
访问 http://ip/域名:9999/ 如下:

默认 admin 用户的密码为 Harbor12345 ,可以在 harbor.cfg 进行修改。登录后如下:

在这里插入图片描述

  1. 上传镜像

首先登录私有仓库,可以使用 admin 用户 ,也可以使用我们自己创建的具有上传权限的用户:

docker login -u admin -p Harbor12345 ip/域名:9999

要通过docker tag将该镜像标志为要推送到私有仓库,例如:

docker tag nginx:latest ip/域名:9999/library/nginx:latest

上传镜像:

docker push ip/域名:9090/library/nginx:latest

访问 http://ip/域名:9999/harbor/projects ,在 library 项目下可以看见刚上传的 nginx镜像了:

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值