【问题标题】:docker pull through cache for private registry not workingdocker pull through cache for private registry 不工作
【发布时间】:2015-09-11 19:43:41
【问题描述】:

我尝试通过 docker 1.8 的注册表 2.1.1 版本中发布的缓存 docker 拉取。在 CentOS7.1 但是,我关注了这些网站,它并没有作为镜像,任何输入将不胜感激。我希望这是配置注册表服务和传递 docker daemon 参数的正确方法。

网站: https://github.com/docker/distribution/blob/master/docs/mirror.md http://docs.master.dockerproject.org/articles/registry_mirror/

步骤:

  1. 我添加了参数以传递给 docker 守护进程并重新启动它:

    # /etc/sysconfig/docker 
    # 
    # Other arguments to pass to the docker daemon process 
    # These will be parsed by the sysv initscript and appended 
    # to the arguments list passed to docker -d
    OPTIONS="--registry-mirror=http://localhost:5000" 
    
  2. 添加注册表配置并挂载到容器:

    version: 0.1
    log:
      fields:
        service: registry
    storage:
        cache:
            blobdescriptor: inmemory
        filesystem:
            rootdirectory: /var/lib/registry
    http:
        addr: :5000
        headers:
            X-Content-Type-Options: [nosniff]
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3
    proxy:
      remoteurl: https://registry-1.docker.io
    
  3. 启动的注册表容器

    docker run -d -p 5000:5000 --restart=always --name registry-mirror -v /opt/docker-registry/local/images:/var/lib/registry -v /opt/docker-registry/local/config/config.yml:/etc/docker/registry/config.yml -e STANDALONE=false -e MIRROR_SOURCE=https://registry-1.docker.io -e MIRROR_SOURCE_INDEX=https://index.docker.io registry:2.1.1
    
  4. 使用如下命令测试通过缓存拉取:

    在我的镜像运行的情况下,拉出一个我以前没有拉过的图像(使用时间来计时)

    从配置为 MIRROR_SOURCE 的 docker hub 拉取

    $ time docker pull busybox:latest
    

    从本地机器中删除图像

    $ docker rmi busybox:latest
    

    最后,这应该从缓存中重新拉取图像,这在我的情况下不起作用,而是从 docker hub 拉取。

    $ time docker pull busybox:latest
    

    我还尝试查看主机文件系统中已安装的图像卷文件夹,但找不到。

    $ ls /opt/docker-registry/local/images/docker/registry/v2/repositories/
    

    尝试对新图像进行 rest api 调用,但返回错误消息:

    $ curl http://localhost:5000/v2/busybox/tags/list     
        {"errors":[{"code":"NAME_UNKNOWN","message":"repository name not known to registry","detail":{"name":"busybox"}}]}
    

【问题讨论】:

  • 有人找到解决这个问题的方法吗? @doss。

标签: docker docker-registry


【解决方案1】:

它对我有用...

docker run -p 5000:5000 \
    -e STANDALONE=false \
    -e MIRROR_SOURCE=https://registry-1.docker.io \
    -e MIRROR_SOURCE_INDEX=https://index.docker.io \
    -e "REGISTRY_LOG_LEVEL=debug" \
    -e "REGISTRY_REDIRECT_DISABLE=true" \
    -v /var/lib/registry:/var/lib/registry \
    --name registry-cache-latest \
    registry

.. 然后将 intg --registry-mirror 指向 http 服务器,而不是 https。

【讨论】:

  • 看它是版本 1,而不是版本 2。我读到版本 1 是 python 中的实现。坚持使用版本 2,我在日志中看到的是一些错误的证书消息。
【解决方案2】:

问题中的 API URL 错误。正确的是:

$ curl http://localhost:5000/v2/library/docker/tags/list

{"name":"library/docker","tags":["1","1-dind","1-experimental","1-experimental-dind","1-e...

对于名称中没有斜线的图像,请使用 library 前缀。如果您的注册表正在响应,它应该可以工作。

在我的示例中,我是这样运行的:

docker run \
        -d \
        -p 5000:5000 \
        --restart=always \
        --name docker-through-cache \
        -v "$PWD/docker-proxy-config.yml:/etc/docker/registry/config.yml" \
        -v /var/docker-registry:/var/docker-registry \
        registry:2

配置:


version: 0.1
proxy:
  remoteurl: https://registry-1.docker.io
storage:
  filesystem:
    rootdirectory: /var/docker-registry
    maxthreads: 100
http:
  addr: 0.0.0.0:5000
log:
  accesslog:
    disabled: true
  level: info
  formatter: text
  fields:
    service: registry

我的 Ubuntu 上的客户端配置位于 /etc/docker/daemon.json 文件中:

{
  "registry-mirrors": ["http://127.0.0.1:5000"]
}

正确配置您的客户端后,存储库日志中将显示以下日志:

time="2021-10-01T07:13:47.130717525Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="127.0.0.1:5000" http.request.id=d9329952-12db-427e-b2c6-346aa8c96425 http.request.method=GET http.request.remoteaddr="172.17.0.1:46142" http.request.uri="/v2/library/docker/blobs/sha256:f7a4137012260e097fc6b4bf6d75ba3b193acb399fb1276687303dea63ba519c" http.request.useragent="docker/20.10.8 go/go1.16.6 git-commit/75249d8 kernel/5.11.0-34-generic os/linux arch/amd64 UpstreamClient(Docker-Client/20.10.8 \(linux\))" http.response.contenttype="application/octet-stream" http.response.duration=451.36281ms http.response.status=200 http.response.written=61283898

当您的客户端下载层时会出现此特定日志(查看 blob 哈希):

$ docker pull docker:20.10.8-dind
20.10.8-dind: Pulling from library/docker
...
f7a413701226: Pull complete
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 2020-08-11
    • 2022-07-09
    • 2015-01-11
    相关资源
    最近更新 更多