Ubuntu 16.04 部署自己的私有 Docker Registry

前端之家收集整理的这篇文章主要介绍了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构建你自己的镜像

猜你在找的Ubuntu相关文章