部署运行Docker-Registry

  • 前提条件

    • 已有docker环境 下载docker
    • Ubuntu 16.04
  • 拉取docker-registry image

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

    • 执行一次下面代码会重新更新 'pwd'/auth/htpasswd (覆盖原来之前的)
    • 如果需要再次添加用户名密码,先备份原有 htpasswd文件 重新运行上面代码,再讲备份文件内容拷入
    • htpasswd文件内容
      部署运行Docker-Registry_第1张图片
      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

你可能感兴趣的:(部署运行Docker-Registry)