部署运行Docker-Registry

  • 前提条件

  • 拉取docker-registry image

    • $ docker pull registry:2
  • 添加docker-registry用户名密码

    • 执行一次下面代码会重新更新 'pwd'/auth/htpasswd (覆盖原来之前的)
    • 如果需要再次添加用户名密码,先备份原有 htpasswd文件 重新运行上面代码,再讲备份文件内容拷入
    • htpasswd文件内容
      htpasswd文件
$ mkdir auth
$ docker run \
    --entrypoint htpasswd \
    registry:2 -Bbn user password > auth/htpasswd
  • 运行docker-registry
    • docker-registry 没有提供可以直接访问的 bash 所以不能通过exec命令进入container直接修改/etc/docker/registry/config.yml(或许可以通过挂载-还未尝试)
      • 官网建议:对于需要覆盖原来 config.yml 中的属性值,可以通过以下方式

To override a configuration option, create an environment variable named REGISTRY_variable where variable is the name of the configuration option and the _ (underscore) represents indention levels.

  • 通过-e 参数以及特定的参数名字可覆盖

    • 以下配置变换后参数(添加配置后,可以通过http DELETE 方法删除image):REGISTRY_STORAGE_DELETE_ENABLED=true
    storage:
       delete:
         enabled: true
    
    
  • 开启docker-registry 命令

$ docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  -v /home/dkongjian/auth:/auth \
  -v /mnt/registry:/var/lib/registry \
  -e "REGISTRY_STORAGE_DELETE_ENABLED=true" \
  -e "REGISTRY_AUTH=htpasswd" \
  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  registry:2
  • docker-registry garbage-collect

    • 通过http DELETE 方法删除后,仅将image及layer标记成deleted 通过registry API 不可见,但实际依然占用磁盘空间,解决方式是使用docker-registry的garbage collect

    Manifests and layers can be deleted with the registry API (refer to the API documentation here and here for details). This API removes references to the target and makes them eligible for garbage collection. It also makes them unable to be read via the API.
    If a layer is deleted it will be removed from the filesystem when garbage collection is run. If a manifest is deleted the layers to which it refers will be removed from the filesystem if no other manifests refers to them.

    • 执行grabage-collect 并且重启
      • 如果不重启,当push曾经push过的images时,速度很快 并且显示 Layer already exists。 但是通过Registry-API get 访问时显示 manifest not exist.
$ docker exec registry /bin/registry garbage-collect /etc/docker/registry/config.yml
$ docker restart registry
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,567评论 5 6
  • 黑夜从大地上升起。燃起一堆篝火,烧出透亮纹理,冲天而起的红,翻转腾挪,围坐着狩猎采集为生的先祖,人类故事从这里开始...
    青豆_Lauren阅读 660评论 0 0
  • 123图书馆是全球最低图书循环成本的创新平台,通过对书籍的循环利用来实现环保目的。同时,它也是全球最好的公益图书馆...
    oriaryy阅读 393评论 0 0
  • 沈华立(正其心),天贝车业,盛和塾224期学员,【日精打卡第35天】 《六项精进》2遍共94遍 《大学》2遍共94...
    沈华立阅读 188评论 0 0
  • 总结 和其他同事一起,这一周我们参与了万方的“销售人员成长阶梯培训”,初步了解了好的销售人员需要什么样的思维方式、...
    甲戊雍阅读 277评论 0 0