环境: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. SpringCloud(2) 服务注册和发现Eureka Server

    一.简介 EureKa在Spring Cloud全家桶中担任着服务的注册与发现的落地实现.Netflix在设计EureKa时遵循着AP原则,它基于REST的服务,用于定位服务,以实现云端中间层服务发现 ...

  2. iframe跨域通信实战

    "长时间不写文章,开头的方式总是那么出奇的相似",最近很忙,好久没写博客了啊(是不是?). 更换工作已经有三个月有余,这段三个月把过去三年没加过的班都加了一次.收获挺多,发现的问题 ...

  3. Java8之Optional类

    写在前头 今天再看阿里的Java开发手册,里面异常处理第10条提到这样一个建议. [推荐]防止 NPE ,是程序员的基本修养,注意 NPE 产生的场景:1 ) 返回类型为基本数据类型,return 包 ...

  4. Shell编程(week4_day2)--技术流ken

    本节内容 1. shell变量简介 2. 定义变量 3. 使用变量 4. 修改变量的值 5. 单引号和双引号的区别 6. 将命令的结果赋值给变量 7. 删除变量 8. 变量类型 9. 特殊变量列表 1 ...

  5. .Net语言 APP开发平台——Smobiler学习日志:如何快速实现按钮组功能

    最前面的话:Smobiler是一个在VS环境中使用.Net语言来开发APP的开发平台,也许比Xamarin更方便 一.目标样式 我们要实现上图中的效果,需要如下的操作: 1.从工具栏上的“Smobil ...

  6. Scrapy爬虫错误日志汇总

    1.数组越界问题(list index out of range) 原因:第1种可能情况:list[index]index超出范围,也就是常说的数组越界. 第2种可能情况:list是一个空的, 没有一 ...

  7. 自定义工作流活动运行产生System.Security.SecurityException

    摘要: 微软动态CRM专家罗勇 ,回复305或者20190224可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 最近碰到一个 ...

  8. Adapter刷新数据的坑

    adapter刷新数据的时候,要能够刷新成功,要保证每次刷新的时候都是改变数据源. 于是,我这样做了,在适配器的构造方法里面写到: private List<ListBean> listI ...

  9. mac /linux vi/vim永久显示行号开启高亮模式

    临时显示:进入vi编辑器,输入命令 :set number     //下次在进入vi 无法显示行号 :set nonumber  //本次vi关闭行号显示 vi 每次修改后推荐使用命令: sourc ...

  10. Oracle的ORA-02292报错:违反完整性约束,已找到子记录

    第一种方法: 第一步就是找到子表的记录: select a.constraint_name, a.table_name, b.constraint_name from user_constraints ...