当前位置:运维

系统环境:ubuntu16.04-x86-64,Host A 用作本地Registry服务器,Host B用作测试客户机,验证到Host A 的push,pull是否正常

系统内核:Linux ubuntu 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x8664 x8664 x86_64 GNU/Linux

docker版本: 17.12.1-ce, build 7390fc6

具体步骤

  1. 启动registry容器

    docker run -d -p 5000:5000 -v /myregistry:/var/lib/registry registry:2

    注释:

    使用docker官方registry镜像的版本为2 registry:2。

    -d 是后台启动容器。

    -p 将registry容器的 5000 端口映射到 Host 的 5000 端口。5000 是 registry 服务端口。

    -v 将registry容器 /var/lib/registry 目录映射到 Host 的 /myregistry【用于存放镜像数据】。

  2. 通过 docker tag 重命名镜像,将host 中已下载或创建的本地容器镜像名映射给本地Registry

    2.1. 查询Host A 中已存在镜像。

    root@ubuntu:~# docker images
    REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
    ubuntu-with-vim                                       latest              0c299c54e878        2 days ago          209MB
    centos-with-vim                                       latest              2abde09863fe        2 days ago          359MB
    registry.example.net:5000/osoulmate/centos-with-vim   v1                  2abde09863fe        2 days ago          359MB
    httpd                                                 latest              01154c38b473        2 weeks ago         177MB
    registry.example.net:5000/osoulmate/httpd             v1                  01154c38b473        2 weeks ago         177MB
    ubuntu                                                latest              0458a4468cbc        5 weeks ago         112MB
    registry                                              2                   d1fd7d86a825        8 weeks ago         33.3MB
    centos                                                latest              ff426288ea90        8 weeks ago         207MB
    hello-world                                           latest              f2a91732366c        3 months ago        1.85kB

    2.2. 将Host A中镜像 hello-world 映射给本地Registry,以使Host B 等客户机可以push,pull 镜像。

    root@ubuntu:~# docker tag hello-world:latest registry.example.net:5000/hello-world:latest

    注释: registry.example.net已在Host A,Host B的/etc/hosts文件中映射为Host A的主机地址

  3. 将hello-world镜像上传到Host A Registry仓库中,以供Host B下载。

    root@ubuntu:~# docker push registry.example.net:5000/hello-world:latest

    注释: hello-world本身已经存在Host A中了,但当前的位置并不能让Host B访问到,所以还要这一步操作哦!

    镜像名称由 repository 和 tag 两部分组成。而 repository 的完整格式为:[registry-host]:[port]/[username]/xxx

    只有 Docker Hub 上的镜像可以省略 [registry-host]:[port] 。

  4. 测试Host B从Host A上拉取hello-world镜像

    root@ubuntu:~# docker pull registry.example.net:5000/hello-world:latest
  5. 查看Host B中hello-world镜像是否已从Host A成功拉取。

小结:

问题一:Error response from daemon: Get https://registry.example.net:5000/v2/: http: server gave HTTP response to HTTPS client

解决方法:在/etc/docker/daemon.json中加入 { "insecure-registries":["registry.example.net:5000"] } 即可解决服务端将http响应返回给https客户端的错误。

评论
一些有趣的事儿