docker private registry[私有仓库]

docker registry不需要联外网建立,本地部署仓库供本地使用,服务器在哪就在哪部署仓库走内网,方便效率高。

docker private registry[私有仓库]创建
为快速创建私有Registry,Docker专门提供了一个名为Docker Distribution的软件包,我们可以通过安装这个软件包快速构建私有仓库。

第一种:使用docker-distribution创建私有仓库
centos8版本中已经没有docker-distribution软件安装,centos7版本存在该安装。
基于centos7版本的docker-distribution自建仓库:

1、下载docker-distribution并修改配置文件
[root@king ~]# yum -y install docker-distribution
[root@king ~]# vim /etc/docker-distribution/registry/config.yml
version: 0.1
log:
  fields:
    service: registry
storage:
    cache:
        layerinfo: inmemory
    filesystem:
        rootdirectory: /var/lib/registry  # 修改此处为一个容量大的磁盘分区目录
http:
    addr: :5000
    
[root@king ~]# systemctl start docker-distribution
[root@king ~]# ss -antl
State       Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port              
LISTEN      0      128                               [::]:5000

2、在king上使用自建的Registry去上传镜像
# 使用insecure-registries参数添加http支持
[root@king ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": ["https://j3m2itm3.mirror.aliyuncs.com","https://registry.docker-cn.com"],
    "insecure-registries": ["king1-linux.example.com:5000"]
}

[root@king ~]# systemctl restart docker
[root@king ~]# docker images
[root@king ~]# docker tag nginx:latest king1-linux.example.com:5000/nginx:latest  //修改标签名
[root@king ~]# docker images
[root@king ~]# docker push king1-linux.example.com:5000/nginx

第二种:官方镜像创建私有仓库

1、运行一个容器,容器是基于官方仓库registry镜像,做端口映射
[root@king ~]# docker run -d -p 5000:5000 registry   //-d运行在后台
[root@king ~]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED          STATUS         PORTS                                       NAMES
14018cc0dbce   registry   "/entrypoint.sh /etc…"   10 seconds ago   Up 9 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   nice_hofstadter
[root@king ~]# ss -anlt|grep 5000
LISTEN    0         128                0.0.0.0:5000             0.0.0.0:*       
LISTEN    0         128                   [::]:5000                [::]:*

2、vi/vim编辑/etc/dokcer/daemon.json 添加insecure-registries:虚拟主机地址:端口号
[root@king ~]# vim /etc/docker/daemon.json
{
            "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/","https://registry.docker-cn.com"],
            "insecure-registries":["192.168.120.128:5000"]
}
[root@king ~]# systemctl daemon-reload 
[root@king ~]# systemctl restart docker

3(重启docker服务后容器会自动停止)因要设置开启自建仓库,上传自创镜像
...修改本地镜像标签,新建个镜像,适用于自建仓库上传
[root@king ~]# docker tag tangq123456/b1:v0.1.1 192.168.120.128:5000/bb1:v0.1    //本地仓库修改标签名
[root@king ~]# docker images
REPOSITORY                 TAG       IMAGE ID       CREATED        SIZE
192.168.120.128:5000/bb1   v0.1      543720452a38   3 weeks ago    1.24MB
...设置自建仓库总是开启
[root@king ~]# docker run --help  //找到--restart
///--restart always命令:总是开启状态
[root@king ~]# docker run -d -p 5000:5000 --restart always registry
[root@king ~]# systemctl restart docker   
[root@king ~]# ss -antl|grep 5000
LISTEN    0         128                0.0.0.0:5000             0.0.0.0:*       
LISTEN    0         128                   [::]:5000                [::]:*
[root@king ~]# docker ps -a    //保证docker服务重启后自建仓库也总是开启的,已生效
CONTAINER ID   IMAGE      COMMAND                  CREATED              STATUS         PORTS                                       NAMES
3ffbabca150d   registry   "/entrypoint.sh /etc…"   About a minute ago   Up 7 seconds   0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   nervous_burnell

4、把新镜像推到自建仓库中
[root@king ~]# docker logout  //因之前用的是官方仓库,所以需要退出,不然会上传到官方仓库中
[root@king ~]# docker push 192.168.120.128:5000/bb1:v0.1
【自建仓库搭建缺点不方便查找镜像不能使用docer命令查询也没有网络页面查看】

🔸Harbor部署 —自建仓库
harbor官方文档资源

harbor部署过程:

[执行以下之前,必需安装docker和加速器]

1、首先安装docker-compose为安装harbor准备工作(因yum找不到安装包,需要安装python38借助pip安装)
[root@king ~]# yum -y install python38
[root@king ~]# pip  //tab键查看pip
pip-3    pip3     pip-3.8  pip3.8
[root@king ~]# pip3 insatll docker-compose   //pip哪个都可安装
...Successfully installed ...   //成功安装docker-compose

2、下载harbor包并解压到指定目录/usr/local
[官网复制包链接↓]
[root@king ~]# wget https://github.com/goharbor/harbor/releases/download/v2.3.2/harbor-offline-installer-v2.3.2.tgz
[或者本地下载好上传harhor包👇]
[root@king ~]# ls
harbor-offline-installer-v2.3.2.tgz 
[root@king ~]# tar xf harbor-offline-installer-v2.3.2.tgz -C /usr/local  //解压到/usr/local(-C指定解压到什么地方)
[root@king ~]# cd /usr/local/harbor/
[root@king harbor]# ls
common.sh  harbor.v2.3.2.tar.gz  harbor.yml.tmpl  install.sh  LICENSE  prepare

3、vim编辑harbor.yml.tmpl配置文件两个内容[hostname和注释https证书]
[root@king harbor]# vim harbor.yml.tmpl  //编辑该文件中以下内容(两个地方)
...
hostname: 192.168.120.128   //改主机名①
port: 80      //端口是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
 ...
 harbor_admin_password: Harbor12345   //此处是给的harbor用户名admin,密码Harbor12345
 ...
 database:    //harbor数据库信息
  # The password for the root user of Harbor DB. Change this before any production use.
  password: root123   //数据库密码
  ...

4、执行harbor自带install.sh脚本文件
[root@king harbor]# ./install.sh   //执行它自带的脚本文件
[Step 4]: preparing harbor configs ...
prepare base dir is set to /usr/local/harbor
no config file: /usr/local/harbor/harbor.yml //会报错找不到文件
[root@king harbor]# cp harbor.yml.tmpl harbor.yml  //拷贝一份更改名字
[root@king harbor]# ./install.sh
✔ ----Harbor has been installed and started successfully.----
5、查看到1514端口被监听
[root@king harbor]# ss -antl    //监听本地端口为1514
State              Recv-Q             Send-Q                         Local Address:Port                         Peer Address:Port            
LISTEN             0                  128                                  0.0.0.0:5000                              0.0.0.0:*               
LISTEN             0                  128                                127.0.0.1:1514                              0.0.0.0:*

5、可以通过IP地址访问到harbor网页
登录用户名和密码在harbor.yml文件中
[root@king harbor]# grep password harbor.yml //过滤password
harbor_admin_password: Harbor12345
在这里插入图片描述
登录后使用harbor的方法:
1、要先登录创建的harbor网页版私有仓库,然后docker login登录客户端再去上传拉取镜像
2、更改客户端配置文件内容指定清楚网页是使用是http或80端口协议登录
[root@king ~]# vim /etc/docker/daemon.json
“insecure-registries”:[“http://192.168.120.128”]
[root@king ~]# systemctl daemon-reload
[root@king ~]# systemctl restart docker
//此时重启完会发现有些容器停止了,必需要在有docker-compose.yml文件的目录下使用该命令开启所有停掉容器
[root@king harbor]# docker-compose start
3、上传镜像到harbor步骤:
①在harbor网页私有仓库中新创建项目
在这里插入图片描述
②在客户端更改镜像名和标签(要跟网页上写的的对应)
//改:网站位置/存放镜像位置/镜像名:版本)
[root@king harbor]# docker tag tangq123456/b1:v0.1.1 192.168.120.128/web/b1:v0.1
[root@king harbor]# docker images |grep v0.1
192.168.120.128/web/b1 v0.1 543720452a38 4 weeks ago 1.24MB
③退出之前登录docker网站,重新登录到harbor网页私有仓库中
[root@king harbor]# docker logout
Removing login credentials for https://index.docker.io/v1/
[root@king harbor]# docker login 192.168.120.128
Username: admin
Password: Harbor12345

Login Succeeded
④上传镜像
[root@king harbor]# docker push 192.168.120.128/web/b1:v0.1
刷新查看网页信息,已上传成功:
在这里插入图片描述
尝试该镜像不存在)从网页拉取镜像:
[root@king harbor]# docker pull 192.168.120.128/web/b1:v0.1
[root@king harbor]# docker images|grep v0.1
192.168.120.128/web/b1 v0.1 543720452a38 4 weeks ago 1.24MB
4、Harbor是使用docker-compose命令来管理的,如果需要停止Harbor也使用docker-compose stop来停止,其他参数 --help

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值