欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker的私有仓库

程序员文章站 2022-03-01 17:28:20
...

创建一个自己的私有仓库,存放自己的镜像

一:构建registry私有仓库

#安装registry仓库
[[email protected]_0_7_centos ~]# docker image pull registry
[[email protected]_0_7_centos ~]# docker run --name my_registry -d -p 5001:5000 registry
#测试(下载一个nginx镜像)
[[email protected]_0_7_centos ~]# docker pull nginx
[[email protected]_0_7_centos ~]# docker tag nginx 139.199.25.216:5001/nginx:test
[[email protected]_0_7_centos ~]# docker images |grep nginx
139.199.25.216:5001/nginx   test                dbfc48660aeb        2 weeks ago         109MB
#上传
[[email protected]_0_7_centos ~]# docker push 139.199.25.216:5001/nginx:test
The push refers to a repository [139.199.25.216:5001/nginx]
Get https://139.199.25.216:5001/v2/: http: server gave HTTP response to HTTPS client
注意:自1.13版本后,默认使用的是https,但是搭建的是http,做如下修改
[[email protected]_0_7_centos ~]# cat /etc/docker/daemon.json 
{
 #加速器
 "registry-mirrors": ["https://registry.docker-cn.com"],
 "insecure-registries":["139.199.25.216:5001"]
}
#重启容器和docker服务
[[email protected]_0_7_centos ~]# systemctl restart docker
[[email protected]_0_7_centos ~]# docker start my_registry
#重新上传
[[email protected]_0_7_centos ~]# docker push 139.199.25.216:5001/nginx:test

二:查看私有仓库中有哪些镜像

1:shell版

[[email protected]_0_7_centos ~]# cat registry_image.sh 
#!/bin/bash
#Author: heitao
#date:2018/11/1

find() {
  if [ $# -ne 1 ];then
     echo "Usage:$0 [Host:port]"
     exit 250
  fi
  
  #获取镜像的名字
  name=`curl -s -XGET http://$1/v2/_catalog`
  
  echo "registry有如下镜像:"
  #根据镜像名字获取标签
  for image in `echo $name|grep -o '\[.*\]'|grep -o '\".*\"'|sed 's/,/\n/g;s/"//g'`
  do
      tag=`curl -s -XGET http://$1/v2/${image}/tags/list`
      echo $tag|awk -F'"' '{print $4":"$8}'
  done
}

find $1

2:python版

[[email protected]_0_7_centos ~]# cat registry_image.py 
#!/usr/bin/env python
#coding:utf-8
#查看私有仓库(registry)中有哪些镜像
 
import commands,sys
import json
 
def find():
    #获取镜像名字字典
    url='curl -s -XGET http://%s/v2/_catalog' %sys.argv[1]
    name_str=commands.getoutput(url)
    name_dict=json.loads(name_str)
 
    name_list=name_dict.values()
    for i in name_list[0]:
        url='curl -s -XGET http://%s/v2/%s/tags/list' %(sys.argv[1],i)
        tag=json.loads(commands.getoutput(url))
        tag_tup=tag.values()[0].encode('utf-8'),tag.values()[1][0].encode('utf-8')
        print(tag_tup[0]+":"+tag_tup[1])
 
if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.exit("Usage:%s [Host:port]"%sys.argv[0])
    else:
        find()

以上就是自己的私有仓库,后期所有的镜像都上传到这里

相关标签: Docker