环境:centos7,dockere版本:18.09.0,镜像仓库:v2

  docker-registry:192.168.137.101   docker私有仓库服务器

  docker-app: 192.168.137.102   运行docker的普通机器

  

一、安装私有仓储

  1. 登录docker私有仓库服务器
  2. 创建私有仓库存储的文件夹,make -p /docker/registry
  3. 执行以下命令,会启动一个registry容器,该容器用于提供私有仓库的服务
docker run -d -p : --name registry-ser --restart=always 
--privileged=true -v /docker/registry:/var/lib/registry registry
  • --restart=always 表示自动启动容器
  • -v <宿主机目录>:<容器目录> 将宿主机的目录映射到容器上
  • --privileged=true 给容器加权限,这样上传就不会因为目录权限出错
  • /var/lib/registry 这个目录是docker私有仓库,镜像的存储目录

--restart的参数说明 
# always:无论容器的退出代码是什么,Docker都会自动重启该容器。 
# on-failure:只有当容器的退出代码为非0值的时候才会自动重启。
#另外,该参数还接受一个可选的重启次数参数,`--restart=on-fialure:5`表示当容器退出代码为非0时,Docker#会尝试自动重启该容器,最多5次。

二、测试

1.接下来,把本地的hello-world镜像push到私有仓储。

docker pull hello-world

2.接下来修改该镜像的tag。

docker tag hello-world 192.168.137.101:5000/hello-world

3.接下来把打了tag的镜像上传到私有仓库。

docker push 192.168.137.101:5000/hello-world

很不幸,这里报错了。因为从docker1.3.2版本开始,使用registry时,必须使用TLS保证其安全。

1月  :: localhost.localdomain dockerd[]: time="2019-01-05T22:32:38.578520907+08:00" 
level=error msg="Handler for GET /v1.39/images/search returned error: invalid registry endpoint
https://192.168.137.101:5000/v1/: Get https://192.168.137.101:5000/v1/_ping: http: server gave
HTTP response to HTTPS client. If this private registry supports only HTTP or HTTPS with an unknown CA certificate,
please add `--insecure-registry 192.168.137.101:5000` to the daemon's arguments. In the case of HTTPS,
if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate
at /etc/docker/certs.d/192.168.137.101:5000/ca.crt"

  最简单的办法是,在需要连接该私有仓库的所有客户端docker宿主机上,修改daemon.json配置文件,增加insecure-registry参数。

[root@localhost ~]# vi /etc/docker/daemon.json 

{
"registry-mirrors": ["https://yvaq2qqy.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.137.101:5000"]
}

  或者直接在 /lib/systemd/system/docker.service 这个启动文件里加上 --insecure-registry 192.168.137.101:5000

[root@localhost system]# cat -n /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service
Wants=network-online.target [Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H unix:// \
--insecure-registry 192.168.137.101: #加上这一句
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=
RestartSec=
Restart=always

  之后重启docker服务:systemctl restart docker

  之后再push,发现成功了。

[root@localhost system]# docker push 192.168.137.101:/hello-world
The push refers to repository [192.168.137.101:/hello-world]
af0b15c8625b: Pushed
latest: digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a size:

三、管理私有镜像

  在Private Registry 2中查看或检索Repository或images,将不能用docker search。

  但通过v2版本的API,我们可以实现相同目的,必须按照IP:port/v2/_catalog格式:

  curl http://192.168.137.101:5000/v2/_catalog 、curl http://192.168.137.101:5000/v2/hello-world/tags/list

  查看私有仓库的信息。

[root@localhost system]# curl http://192.168.137.101:5000/v2/_catalog
{"repositories":["hello-world"]} [root@localhost system]# curl http://192.168.137.101:5000/v2/hello-world/tags/list
{"name":"hello-world","tags":["latest"]} #从私有仓储里拉取hello-world镜像
[root@localhost system]# docker pull 192.168.137.101:5000/hello-world
Using default tag: latest
latest: Pulling from hello-world
Digest: sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a
Status: Image is up to date for 192.168.137.101:5000/hello-world:latest
 

docker私有镜像仓库搭建的更多相关文章

  1. 基于 registry 搭建 Docker 私有镜像仓库

    今天主要介绍使用 registry 来搭建 Docker私有镜像仓库,方便在公司内部项目中使用,registry 也是 Docker 官方提供的一个镜像,操作也很简单. dockerhub: http ...

  2. 6.云原生之Docker容器Registry私有镜像仓库搭建实践

    转载自:https://www.bilibili.com/read/cv15219863/?from=readlist #1.下载registry仓库并设置数据存放的目录(并生成认证账号密码) doc ...

  3. Docker 私有镜像仓库的搭建及认证

    DockerHub 为我们提供了很多官方镜像和个人上传的镜像,我们可以下载机构或个人提供的镜像,也可以上传我们自己的本地镜像,但缺点是: 由于网络的原因,从 DockerHub 下载和上传镜像速度可能 ...

  4. 使用Nexus3构建Docker私有镜像仓库

    一.安装Nexus3 Nexus3是Sonatype提供的仓库管理平台,Nuexus Repository OSS3能够支持Maven.npm.Docker.YUM.Helm等格式数据的存储和发布:并 ...

  5. nexus docker 私有镜像处理

    新版本的nexus 可以进行docker 镜像的存储处理 配置私有镜像(host 模式) 修改docker 非安全镜像处理 { "registry-mirrors": [" ...

  6. VMware harbor && minio 搭建企业docker私有镜像以及需要注意的问题

    1. docker harbor  配置      建议使用在线安装的模式(离线包太大了)    首先需要安装docker-compose .docker .mino (具体安装可以参考官网后者我的博 ...

  7. 容器技术之Docker私有镜像仓库docker-distribution

    在前边的博客中我们说到docker的架构由docker客户端.服务端以及仓库组成:docker仓库就是用来存放镜像的地方:其实docker registry我们理解为存放docker镜像仓库的仓库比较 ...

  8. 容器技术之Docker私有镜像仓库harbor

    前文我们聊到了docker的私有镜像仓库docker-distribution的搭建和简单的使用,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13058338 ...

  9. 【Linux】【Services】【SaaS】Docker+kubernetes(7. 安装Docker私有镜像仓库)

    1. 简介 1.1. 自己做个私有镜像,方便上传和下载,我也在docker官网注册了一个账号,做好的镜像可以传上去 1.2. Redhat自带私有镜像的功能,需要安装包,这是howto: https: ...

随机推荐

  1. c语言之gdb调试。

    1.此文档演示如何使用gdb调试c语言代码. 代码如下: #include <stdio.h> /*函数声明*/ void digui(int n); int main() { ; dig ...

  2. webpack4.0各个击破(5)—— Module篇

    webpack4.0各个击破(5)-- Module篇 webpack作为前端最火的构建工具,是前端自动化工具链最重要的部分,使用门槛较高.本系列是笔者自己的学习记录,比较基础,希望通过问题 + 解决 ...

  3. 第2章 术语 - Identity Server 4 中文文档(v1.0.0)

    规范.文档和对象模型等都使用特定的术语来表述. 2.1 IdentityServer IdentityServer是OpenID Connect提供程序 - 它实现OpenID Connect和OAu ...

  4. [转]eShopOnContainers 看微服务 ①:总体概览

    本文转自:https://www.cnblogs.com/tianyamoon/p/10081177.html 一.简介 eShopOnContainers是一个简化版的基于.NET Core和Doc ...

  5. 重写(override)和重载(overload)的区别

    override(重写): 是进行基类中函数的重写,是面向对象的概念 重载(overload):是方法的名称相同,参数或参数类型不同,进行多次重载以适应不同的需要.overload 是面向对象的概念.

  6. 服务器控件的几个属性 SelectedIndex、SelectedItem、SelectedValue、SelectedItem.Text、selectedItem.value

    转自http://blog.csdn.net/iqv520/article/details/4419186 1. SelectedIndex ——选项的索引,为int,从0开始,可读可写 2. Sel ...

  7. 关于HTTP中GET与POST的区别

    GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 看似很简单,其实是一道送命题 “标准答案”: GET在浏览器回退时是无害的,而POST会再次提交请求. ...

  8. java框架之springboot

    快速入门 一.helloworld示例 二.springboot单元测试 三.springboot热部署 web开发 整合redis thymeleaf使用 spring-data-jpa使用 整合m ...

  9. python 生成图形验证码

    文章链接:https://mp.weixin.qq.com/s/LYUBRNallHcjnhJb1R3ZBg 日常在网站使用过程中经常遇到图形验证,今天准备自己做个图形验证码,这算是个简单的功能,也适 ...

  10. 随意下载:afinal jar

    刚才用到afinal,下载jar包到处要积分啥的,我花钱下载了,现在免费给兄弟们 链接: https://pan.baidu.com/s/1BmB-06ui1D2BfooUCi6xKg 提取码: m3 ...