博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ubuntu 16.04 部署自己的私有 Docker Registry
阅读量:7108 次
发布时间:2019-06-28

本文共 6804 字,大约阅读时间需要 22 分钟。

hot3.png

1. 目录结构示例

root@koalaphp:~# tree docker/docker/|-- auth|   `-- htpasswd|-- config.yml|-- docker-compose.yml`-- registry2 directories, 3 filesroot@koalaphp:~#

2. 编写Registry的配置文件

不妨这个配置文件叫做【config.yml】

version: 0.1log:  fields:    service: registrystorage:  cache:    blobdescriptor: inmemory  filesystem:    rootdirectory: /var/lib/registry  maintenance:    readonly:      enabled: falsehttp:  addr: :5000  headers:    X-Content-Type-Options: [nosniff]health:  storagedriver:    enabled: true    interval: 10s    threshold: 3auth:  htpasswd:    realm: basic-realm    path: /auth/htpasswd

3. 配置http basic auth 认证

生成认证的文件【htpasswd -cB auth/htpasswd read】

root@koalaphp:~/docker# htpasswd -cB auth/htpasswd readNew password: Re-type new password: Adding password for user readroot@koalaphp:~/docker#

4. docker-compose.yml配置文件

version: "2"services:  registry_server:     image: registry     ports:       - 5000:5000    restart: "always"    volumes:      - /root/docker/registry:/var/lib/registry      - /root/docker/config.yml:/etc/docker/registry/config.yml      - /root/docker/auth:/auth

5. 开始启动服务

为了支持docker-compose,很简单的仅需要执行一条命令

pip install docker-compose

测试是否安装成功

root@koalaphp:~/docker# docker-compose versiondocker-compose version 1.15.0, build e12f3b9docker-py version: 2.5.1CPython version: 2.7.12OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016root@koalaphp:~/docker#

常用命令就俩,启动命令【docker-compose up】、停止命令【docker-compose down】

root@koalaphp:~/docker# docker-compose upCreating network "docker_default" with the default driverCreating docker_registry_server_1 ... Creating docker_registry_server_1 ... doneAttaching to docker_registry_server_1registry_server_1  | time="2017-08-27T14:57:57Z" level=warning msg="No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable." go.version=go1.7.6 instance.id=b024503a-525e-4fb6-8ada-6087d8683eb9 version=v2.6.2 registry_server_1  | time="2017-08-27T14:57:57Z" level=info msg="redis not configured" go.version=go1.7.6 instance.id=b024503a-525e-4fb6-8ada-6087d8683eb9 version=v2.6.2 registry_server_1  | time="2017-08-27T14:57:57Z" level=info msg="Starting upload purge in 13m0s" go.version=go1.7.6 instance.id=b024503a-525e-4fb6-8ada-6087d8683eb9 version=v2.6.2 registry_server_1  | time="2017-08-27T14:57:57Z" level=info msg="using inmemory blob descriptor cache" go.version=go1.7.6 instance.id=b024503a-525e-4fb6-8ada-6087d8683eb9 version=v2.6.2 registry_server_1  | time="2017-08-27T14:57:57Z" level=info msg="listening on [::]:5000" go.version=go1.7.6 instance.id=b024503a-525e-4fb6-8ada-6087d8683eb9 version=v2.6.2

 

6. 推送镜像入库

root@koalaphp:~/docker# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEmyip                1.0                 506286302b58        7 hours ago         136.4 MBubuntu              16.04               ccc7a11d65b1        2 weeks ago         120.1 MBregistry            latest              751f286bc25e        5 weeks ago         33.19 MBroot@koalaphp:~/docker# docker tag myip:1.0 koalaphp.com:5000/myip:1.0root@koalaphp:~/docker# docker imagesREPOSITORY               TAG                 IMAGE ID            CREATED             SIZEkoalaphp.com:5000/myip   1.0                 506286302b58        7 hours ago         136.4 MBmyip                     1.0                 506286302b58        7 hours ago         136.4 MBubuntu                   16.04               ccc7a11d65b1        2 weeks ago         120.1 MBregistry                 latest              751f286bc25e        5 weeks ago         33.19 MBroot@koalaphp:~/docker# docker push koalaphp.com:5000/myip:1.0The push refers to a repository [koalaphp.com:5000/myip]15a01deab661: Image push failed a09947e71dc0: Image push failed 9c42c2077cde: Image push failed 625c7a2a783b: Image push failed 25e0901a71b8: Image push failed 8aa4fcad5eeb: Image push failed no basic auth credentialsroot@koalaphp:~/docker# docker login koalaphp.com:5000Username: readPassword: Login Succeededroot@koalaphp:~/docker# docker push koalaphp.com:5000/myip:1.0The push refers to a repository [koalaphp.com:5000/myip]15a01deab661: Pushed a09947e71dc0: Pushed 9c42c2077cde: Pushed 625c7a2a783b: Pushed 25e0901a71b8: Pushed 8aa4fcad5eeb: Pushed 1.0: digest: sha256:b88d91224bdd49ce1524b23937ab8d53cd1fd183de08e8538f89271fb849835b size: 1568root@koalaphp:~/docker# docker imagesREPOSITORY               TAG                 IMAGE ID            CREATED             SIZEmyip                     1.0                 506286302b58        7 hours ago         136.4 MBkoalaphp.com:5000/myip   1.0                 506286302b58        7 hours ago         136.4 MBubuntu                   16.04               ccc7a11d65b1        2 weeks ago         120.1 MBregistry                 latest              751f286bc25e        5 weeks ago         33.19 MBroot@koalaphp:~/docker# curl --user read:read http://koalaphp.com:5000/v2/_catalog{"repositories":["myip"]}root@koalaphp:~/docker#

 

7. 客户端的配置

修改配置文件:【/etc/docker/daemon.json】

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

重启docker daemon服务

systemctl daemon-reload && systemctl restart docker

测试http是否通

[root@localhost docker]# curl --user read:read http://koalaphp.com:5000/v2/_catalog{"repositories":["myip"]}[root@localhost docker]#

 

8. 本地客户端拉取镜像

[root@localhost docker]# docker login koalaphp.com:5000Username: readPassword: Login Succeeded[root@localhost docker]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEnginx               latest              b8efb18f159b        4 weeks ago         107MBhello-world         latest              1815c82652c0        2 months ago        1.84kB[root@localhost docker]# docker pull koalaphp.com:5000/myip:1.01.0: Pulling from myip95f4beaf4746: Pull complete a654f24b2f04: Pull complete 6d60ad169b64: Pull complete 2549c6d5adc7: Pull complete c57bab9f2a29: Pull complete b54835f7702a: Pull complete Digest: sha256:b88d91224bdd49ce1524b23937ab8d53cd1fd183de08e8538f89271fb849835bStatus: Downloaded newer image for koalaphp.com:5000/myip:1.0[root@localhost docker]# docker imagesREPOSITORY               TAG                 IMAGE ID            CREATED             SIZEkoalaphp.com:5000/myip   1.0                 506286302b58        6 hours ago         136MBnginx                    latest              b8efb18f159b        4 weeks ago         107MBhello-world              latest              1815c82652c0        2 months ago        1.84kB[root@localhost docker]#

 

9. 参考资料

我的相关博客推荐,前期docker相关操作知识储备:

 

转载于:https://my.oschina.net/laiconglin/blog/1524665

你可能感兴趣的文章
ExtJS应用架构设计(二)
查看>>
基于Windows Media Service的流媒体直播系统
查看>>
Exchange Server 2016预览版自动化部署及简单体验
查看>>
VMware Workstation 12-虚拟机-批量创建-快照-批量创建恢复
查看>>
路漫漫其修远兮,吾将上下而求索
查看>>
7年Microsoft MVP,是否还能坚持3年
查看>>
基于IP SAN的ISCSI的存储系统
查看>>
VMware View 5.0从菜鸟到高手系列 3 -安装View Composer组件篇
查看>>
从hao123新logo看导航网站发展趋势
查看>>
十年IT运维谈(一):“爆炸式”PK“渐进式”,谁动了我们的运维?
查看>>
如何寻找高质量流量日入三百+
查看>>
云在天之南——我的七天七夜(率性苍山洱海)
查看>>
PROMISE公司CEO李志恩:云计算要看长期投资回报
查看>>
ASP.NET MVC 5 - 查询Details和Delete方法
查看>>
wince -- windows embedded compact 7 移植成功
查看>>
【翻译】(14)Stable APIs
查看>>
用c socket 方式下载网页
查看>>
[转]android 发送短信和打电话的方法
查看>>
循序渐进全球化:支持 Unicode
查看>>
新浪微博中的特殊符号解释
查看>>