Ubuntu 16.04 部署自己的私有 Docker Registry

1. 目录结构示例

root@koalaphp:~# tree docker/
docker/
|-- auth
|   `-- htpasswd
|-- config.yml
|-- docker-compose.yml
`-- registry

2 directories, 3 files
root@koalaphp:~# 

2. 编写Registry的配置文件

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

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

3. 配置http basic auth 认证

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

root@koalaphp:~/docker# htpasswd -cB auth/htpasswd read
New password: 
Re-type new password: 
Adding password for user read
root@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 version
docker-compose version 1.15.0, build e12f3b9
docker-py version: 2.5.1
CPython version: 2.7.12
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
root@koalaphp:~/docker# 

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

root@koalaphp:~/docker# docker-compose up
Creating network "docker_default" with the default driver
Creating docker_registry_server_1 ... 
Creating docker_registry_server_1 ... done
Attaching to docker_registry_server_1
registry_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 images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
myip                1.0                 506286302b58        7 hours ago         136.4 MB
ubuntu              16.04               ccc7a11d65b1        2 weeks ago         120.1 MB
registry            latest              751f286bc25e        5 weeks ago         33.19 MB
root@koalaphp:~/docker# docker tag myip:1.0 koalaphp.com:5000/myip:1.0
root@koalaphp:~/docker# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
koalaphp.com:5000/myip   1.0                 506286302b58        7 hours ago         136.4 MB
myip                     1.0                 506286302b58        7 hours ago         136.4 MB
ubuntu                   16.04               ccc7a11d65b1        2 weeks ago         120.1 MB
registry                 latest              751f286bc25e        5 weeks ago         33.19 MB
root@koalaphp:~/docker# docker push koalaphp.com:5000/myip:1.0
The 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 credentials
root@koalaphp:~/docker# docker login koalaphp.com:5000
Username: read
Password: 
Login Succeeded
root@koalaphp:~/docker# docker push koalaphp.com:5000/myip:1.0
The 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: 1568
root@koalaphp:~/docker# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
myip                     1.0                 506286302b58        7 hours ago         136.4 MB
koalaphp.com:5000/myip   1.0                 506286302b58        7 hours ago         136.4 MB
ubuntu                   16.04               ccc7a11d65b1        2 weeks ago         120.1 MB
registry                 latest              751f286bc25e        5 weeks ago         33.19 MB
root@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:5000
Username: read
Password: 
Login Succeeded
[root@localhost docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              b8efb18f159b        4 weeks ago         107MB
hello-world         latest              1815c82652c0        2 months ago        1.84kB
[root@localhost docker]# docker pull koalaphp.com:5000/myip:1.0
1.0: Pulling from myip
95f4beaf4746: Pull complete 
a654f24b2f04: Pull complete 
6d60ad169b64: Pull complete 
2549c6d5adc7: Pull complete 
c57bab9f2a29: Pull complete 
b54835f7702a: Pull complete 
Digest: sha256:b88d91224bdd49ce1524b23937ab8d53cd1fd183de08e8538f89271fb849835b
Status: Downloaded newer image for koalaphp.com:5000/myip:1.0
[root@localhost docker]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
koalaphp.com:5000/myip   1.0                 506286302b58        6 hours ago         136MB
nginx                    latest              b8efb18f159b        4 weeks ago         107MB
hello-world              latest              1815c82652c0        2 months ago        1.84kB
[root@localhost docker]# 

 

9. 参考资料

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

1. CentOS 7安装Docker

2. 编写Dockerfile构建你自己的镜像

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值