Docker私有仓库搭建

简介: Docker私有仓库搭建一、制作镜像:(2步完成)第一步:下载仓库镜像docker pull registry第二步:启动docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry说明默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下。

Docker私有仓库搭建

一、制作镜像:(2步完成)

第一步:下载仓库镜像

docker pull registry

第二步:启动

docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry

说明默认情况下,会将仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失,所以我们一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下。

私有仓库搭建完成。

详细日志如下:

[root@helloword ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
49388a8c9c86: Pull complete 
e4d43608dd22: Pull complete 
3a41740f900c: Pull complete 
e16ef4b76684: Pull complete 
65f212f7c778: Pull complete 
Digest: sha256:d837de65fd9bdb81d74055f1dc9cc9154ad5d8d5328f42f57f273000c402c76d
Status: Downloaded newer image for registry:latest
[root@helloword ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
d4ecd71b2c08b293504bb85c43d347c9e1e6cedda157e63586562d13b5a2655f

二、私有仓库使用:

<font color="blue">上传(两步)</font>

第一步,打标签(本地任意镜像,打一个标签,我这里用 hello-world)

docker pull hello-world
docker tag hello-world 127.0.0.1:5000/hello-world

第二步,push上去:

docker push 127.0.0.1:5000/hello-world

上传成功

简单说明:
如果是别的机器要上传,那么ip就要是本机的ip,不能使用127.0.0.1 , 这里只是举个例子。

<font color="blue">下载</font>

** pull下来:**

docker pull 127.0.0.1:5000/hello-world

详细日志:

[root@helloword ~]# docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete 
Digest: sha256:5cf8f274a86b7a22a853c8031b8da47a32135b6f266a2a6777c68483ab728679
Status: Downloaded newer image for hello-world:latest
[root@helloword ~]# docker tag hello-world 127.0.0.1:5000/hello-world
[root@helloword ~]# docker push 127.0.0.1:5000/hello-world
The push refers to a repository [127.0.0.1:5000/hello-world]
f999ae22f308: Pushed 
latest: digest: sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b size: 524
[root@helloword ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
127.0.0.1:5000/hello-world   latest              f2a91732366c        10 hours ago        1.85kB
hello-world                  latest              f2a91732366c        10 hours ago        1.85kB
[root@helloword ~]# docker rmi 127.0.0.1:5000/hello-world
Untagged: 127.0.0.1:5000/hello-world:latest
Untagged: 127.0.0.1:5000/hello-world@sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b
[root@helloword ~]# docker pull 127.0.0.1:5000/hello-world
Using default tag: latest
latest: Pulling from hello-world
Digest: sha256:8072a54ebb3bc136150e2f2860f00a7bf45f13eeb917cca2430fcd0054c8e51b
Status: Downloaded newer image for 127.0.0.1:5000/hello-world:latest

如果有出现报错,可能是因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。
不同的系统,解决方式不一样,简单的百度一下即可。(TODO 后续补充)

三、私有仓库管理:(方式很多,这里介绍几种)

1)使用命令的方式查看镜像:ip可以变

[root@helloword ~]# curl http://127.0.0.1:5000/v2/_catalog
{"repositories":["hello-world"]}

2)pyhton的方式查看:

#-*- coding:utf-8 -*-
#!/usr/local/bin/python python
'''
Created on 2017.07.08
@author: wzw
@desc: get images name from registry
'''
 
import requests
import json
import traceback
 
repo_ip = '47.96.2.146'
repo_port = 5000
 
def getImagesNames(repo_ip,repo_port):
    docker_images = []
    try:
        url = "http://" + repo_ip + ":" +str(repo_port) + "/v2/_catalog"
        res =requests.get(url).content.strip()
        res_dic = json.loads(res)
        images_type = res_dic['repositories']
        for i in images_type:
            url2 = "http://" + repo_ip + ":" +str(repo_port) +"/v2/" + str(i) + "/tags/list"
            res2 =requests.get(url2).content.strip()
            res_dic2 = json.loads(res2)
            name = res_dic2['name']
            tags = res_dic2['tags']
            for tag in tags:
                docker_name = str(repo_ip) + ":" + str(repo_port) + "/" + name + ":" + tag
                docker_images.append(docker_name)
                print (docker_name)
    except:
        traceback.print_exc()
    return docker_images
 
a=getImagesNames(repo_ip, repo_port)
# print a

执行 python2 xxx.py
3)使用工具查看 Humpback
https://www.cnblogs.com/humin/p/6970212.html

目录
相关文章
|
18天前
|
Docker 容器
Docker自建仓库之Harbor高可用部署实战篇
关于如何部署Harbor高可用性的实战教程,涵盖了从单机部署到镜像仓库同步的详细步骤。
58 15
Docker自建仓库之Harbor高可用部署实战篇
|
18天前
|
存储 测试技术 数据安全/隐私保护
Docker自建仓库之Harbor部署实战
关于如何部署和使用Harbor作为Docker企业级私有镜像仓库的详细教程。
37 12
|
18天前
|
Docker 容器
Docker Hub镜像公共仓库使用
这篇文章介绍了如何使用Docker Hub公共仓库进行镜像的创建、上传、下载和管理。
302 8
|
18天前
|
运维 数据安全/隐私保护 Docker
Docker自建仓库之Docker Registry部署实战
关于如何使用Docker Registry镜像搭建本地私有Docker仓库的实战教程,包括了下载镜像、创建授权目录和用户名密码、启动Registry容器、验证端口和容器、测试登录仓库、上传和下载镜像的详细步骤。
66 5
|
26天前
|
存储 Docker 容器
阿里云私有docker仓库构建海外镜像
【8月更文挑战第25天】
108 3
|
2月前
|
存储 Docker 容器
入职必会-开发环境搭建50-Docker必会搭建Docker私有仓库
Docker官方的Docker hub(https://hub.docker.com)是一个用于管理公共镜像的仓库,我们可以从上面拉取镜像到本地也可以把我们自己的镜像推送上去。但是有时候我们的服务器无法访问互联网或者不希望将自己的镜像放到公网当中,那么我们就需要搭建自己的Docker私有仓库来存储和管理自己的Docker镜像。
入职必会-开发环境搭建50-Docker必会搭建Docker私有仓库
|
17天前
|
应用服务中间件 nginx 数据安全/隐私保护
使用Harbor搭建Docker私有仓库
Harbor是一款开源的企业级Docker仓库管理工具,分为私有与公有仓库两种类型,其中私有仓库被广泛应用于运维场景。Harbor提供图形化界面,便于直观操作,并且其核心组件均由容器构建而成,因此安装时需预先配置Docker及docker-compose。Harbor支持基于项目的用户与仓库管理,实现细粒度的权限控制;具备镜像复制、日志收集等功能,并可通过UI直接管理镜像,支持审计追踪。部署Harbor涉及配置文件调整、登录认证等步骤,并可通过客户端进行镜像的上传、拉取等操作。系统内置多种角色,包括受限访客、访客、开发者、维护人员及管理员,以满足不同场景下的使用需求。
71 0
|
2月前
|
Ubuntu Java Docker
docker 搭建私有仓库并发布私有镜像
docker 搭建私有仓库并发布私有镜像
257 1
|
1月前
|
jenkins 网络安全 持续交付
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
Jenkins Pipeline 流水线 - 上传文件 Publish over SSH + Docker 编译 + 上传到阿里仓库
26 0
|
1月前
|
Java 数据安全/隐私保护 Docker
SpringBoot Docker 发布到 阿里仓库
SpringBoot Docker 发布到 阿里仓库
33 0