说明:本文中私有仓库的ip地址为10.10.172.203:5000,操作系统为CentOS7.2;

服务端:10.10.172.203/24

1、从Docker官方仓库里下载registry镜像

1
# docker pull registry

2、docker images命令查看本地镜像;

1
2
3
[root@docker ~]# docker images  
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
registry            latest              d1fd7d86a825        2 weeks ago         33.3MB

默认情况下,会将私有仓库存放于容器内的/tmp/registry目录下,这样如果容器被删除,则存放于容器中的镜像也会丢失。

所以一般情况下会指定本地一个目录挂载到容器内的/tmp/registry下,命令如下:

1
docker run -d -it --restart always --name docker-hub -p 5000:5000 -v /docker-hub/registry:/var/lib/registry registry

查看容器运行

1
2
3
[root@docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
048805afbcf1        registry            "/entrypoint.sh /etc…"   11 seconds ago      Up 8 seconds        0.0.0.0:5000->5000/tcp   docker-hub

由上可以看到,已经启动了一个容器,地址为:10.10.172.203:5000。

3、由于仓库与客户端的https问题,需要修改/usr/lib/systemd/system/docker.service文件,添加 ExecStart=/usr/bin/dockerd --registry-mirror=http://019a7061.m.daocloud.io  --insecure-registry 10.10.172.203:5000

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[root@docker ~]# cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
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 --storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true --registry-mirror=http://019a7061.m.daocloud.io  --insecure-registry 10.10.172.203:5000
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
[root@docker ~]
或者
[root@docker ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["http://df98fb04.m.daocloud.io"],
"insecure-registries":["10.10.172.203:5000"
}
[root@docker ~]#
重新加载docker服务
[root@docker ~]# systemctl daemon-reload
[root@docker ~]# systemctl restart docker 
注:因为Docker从1.3.X之后,与docker registry交互默认使用的是https,然而此处搭建的私有仓库只提供http服务,所以当与私有仓库交互时就会报上面的错误。
为了解决这个问题需要在启动docker server时增加启动参数为默认使用http访问。
需要在docker的配置文件/etc/sysconfig/docker (ubuntu系统中的docker配置文件时/etc/default/docker )添加参数“--insecure-registry=10.10.172.203:5000”。
温馨提示:
这个是在客户机的docker配置文件里添加的(即上传镜像到私有仓库里或从私有仓库下载镜像的客户机)。

4、重新启动docker。(如果是在虚拟机中运行,重启一下虚拟机,要不然还是使用其他机器访问此仓库还是会有https的问题)

1
# systemctl restart docker

5、docker tag将镜像打tag,语法格式如下

1
docker tag <image_name> <registry_ip>:5000/<image_name>:<version>
1
# docker tag centos:latest 10.10.172.203:5000/centos7    //修改了tag后的镜像若要删除,docker rmi后面不能用镜像ID了,需要用docker rmi 10.10.172.203:5000/centos7:latest
1
2
3
4
5
[root@docker ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
registry                     latest              d1fd7d86a825        3 weeks ago         33.3MB
10.10.172.203:5000/centos7   latest              ff426288ea90        3 weeks ago         207MB
centos                       latest              ff426288ea90        3 weeks ago         207MB

6、镜像的上传与下载,语法格式如下

1
2
docker push <registry_ip>:5000/<image_name>:<version>;上传镜像至私有仓库
docker pull <registry_ip>:5000/<image_name>:<version>;从私有仓库pull镜像

1
# docker push 10.10.172.203:5000/centos7
1
2
3
4
5
[root@docker ~]# docker push 10.10.172.203:5000/centos7
The push refers to repository [10.10.172.203:5000/centos7]
e15afa4858b6: Pushed 
latest: digest: sha256:7e94d6055269edb455bcfb637292573117e4a8341e9b9abbc09b17d8aafe8fbe size: 529
[root@docker ~]#

7、使用curl 10.10.172.203:5000/v2/_catalog 查看仓库中的镜像情况

1
2
3
[root@docker ~]# curl 10.10.172.203:5000/v2/_catalog
{"repositories":["centos7"]}
[root@docker ~]#

注意查看镜像方法(docker pull registry:2.1.1):

1
2
# curl -XGET http://registry_ip:5000/v2/_catalog
# curl -XGET http://registry_ip:5000/v2/image_name/tags/list

客户端下载私有仓库镜像:

  1. 配置docker信任私有仓库地址(http)

1
2
3
4
5
[root@localhost ~]# cat /etc/docker/daemon.json 
{
"registry-mirrors": ["http://df98fb04.m.daocloud.io"],
"insecure-registries":["10.10.172.203:5000"]
}


2.查看客户端本机镜像列表

1
2
3
[root@localhost ~]# docker images               
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              ff426288ea90        3 weeks ago         207MB

3.从私有仓库下载centos镜像

1
2
3
4
5
[root@localhost ~]# docker pull 10.10.172.203:5000/centos7
Using default tag: latest
latest: Pulling from centos7
Digest: sha256:7e94d6055269edb455bcfb637292573117e4a8341e9b9abbc09b17d8aafe8fbe
Status: Downloaded newer image for 10.10.172.203:5000/centos7:latest

4.再次查看客户端本机镜像列表

1
2
3
4
5
[root@localhost ~]# docker images
REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
10.10.172.203:5000/centos7   latest              ff426288ea90        3 weeks ago         207MB
centos                       latest              ff426288ea90        3 weeks ago         207MB
[root@localhost ~]#

总结:使用企业内部私有镜像仓库中的镜像,大大节省了镜像下载的时间。



本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/2067156,如需转载请自行联系原作者

docker-ce私有仓库搭建相关推荐

  1. habor-deploy docker https 私有仓库搭建

    habor-deploy docker https 私有仓库搭建 环境要求 Python 2.7 以上 Docker 1.10以上 Docker Compose 1.6.0 以上 Openssl 开放 ...

  2. docker的私有仓库搭建、compose项目、swarm集群、一键部署docker节点

    1.私有仓库搭建 首先需要一个registry 镜像 [root@foundation24 docker]# docker images registry REPOSITORY TAG IMAGE I ...

  3. docker本地私有仓库搭建

    pull registry镜像并启动成容器 sudo docker run -d -p 5000:5000 –restart=always –name registry -v pwd/data:/va ...

  4. docker registry私有仓库搭建(为k3s准备)

    #docker-compose.yml内容 zxl@debian:~/develop/docker-registry-install$ cat docker-compose.yml version: ...

  5. Docker的使用(四:Docker Registry本地私有仓库搭建知识点总结)

    任务一: Docker Registry本地私有仓库搭建 1.启动Docker Registry: 2.重命名镜像: 3.推送镜像: 4.浏览器查看验证: 5.文件查看验证: 任务二:Docker R ...

  6. Docker Registry本地私有仓库搭建

    相比Docker Hub而言,Docker Registry的功能就不够全面了,且需要自己手动配置.升级.维护和管理,所以说对于Docker镜像管理不太熟悉的人员推荐使用Docker Hub.如果开发 ...

  7. Docker的私有镜像仓库搭建

    Docker的私有镜像仓库搭建 一.配置镜像仓库服务器yum仓库 1.安装docker环境包 2.安装关于的dokcer的yum仓库 3.测试yum仓库 二.安装docker包 三.下载registr ...

  8. Docker私有仓库搭建与配置

    docker pull registry docker run ‐di ‐‐name=registry ‐p 5000:5000 registry 此步用于让 docker信任私有仓库地址 打开浏览器 ...

  9. Centos7 Docker私有仓库搭建

    Centos7 Docker私有仓库搭建 仓库:集中存放镜像的地方,可分为公共仓库和私有仓库 (公共仓库"http://hub.docker.com"或国内的"http: ...

  10. Docker 私有仓库搭建

    2019独角兽企业重金招聘Python工程师标准>>> 文章首发于公众号<程序员果果> 地址:https://mp.weixin.qq.com/s/tBh6kT4I5Xn ...

最新文章

  1. sun.jersey使用Jackson转换数据
  2. jquery如何判断div是否隐藏
  3. C#_获取文件路径中的文件名_扩展名
  4. 转:A/B测试:实现方法
  5. 使用加密工具类进行有效的字符串加密——CSDN博客
  6. hello python的代码,python基础教程之Hello World!
  7. 组装电脑配置单报价_组装电脑配置单推荐,性价比高的游戏、画图和办公全能配置电脑!...
  8. Spring解决bean之间的循环依赖(循环引用)
  9. Java面试必问!Spring事务扩展机制(2)
  10. Dynamics 365 Customer Engagement中插件的调试
  11. 1.Kubernetes权威指南 --- Kubernetes入门
  12. RDS PG如何安装DTS需要的增量迁移插件?
  13. sql分页查询与offset的使用
  14. 【面向对象】UML类图、用例图、顺序图、活动图、状态图、通信图、构件图、部署图
  15. Python利用结巴分词进行中文分词
  16. 城市与城乡规划用地分类和色块标准|CSV|C#程序|Excel
  17. 快恢复二极管工作原理、反向恢复时间详解
  18. php使用excel公式,使用PHPExcel上的公式问题(Excel2007)
  19. 马克思趣味数学题用java_在马克思手稿中有一道趣味的数学问题
  20. TypeScript代理模式/委托模式

热门文章

  1. Mac下显示隐藏文件
  2. HTML/CSS/动画
  3. Linux vim使用心得--一些高级话题
  4. C0302 将一个代码块中的内容保存在文件中, 查看一个rpm包是否可以安装
  5. gbk编码的简介以及针对gbk文本飘红截断原理以及实现
  6. PHP函数 -字符串函数
  7. ExtJs UI框架学习三
  8. Eclipse配置工程自动执行ant实现热部署
  9. 关于 Qt 5,你所需要了解的基础知识
  10. RabbitMQ惰性队列