创建密码

docker pull httpd:latest
#使用httpd创建密码
docker run --entrypoint htpasswd httpd:latest -Bbn username password > ./auth/passwd
#添加新用户
docker run --entrypoint htpasswd httpd:latest -Bbn username password >> ./auth/passwd

#htpasswd命令参考
https://blog.csdn.net/hxpjava1/article/details/79580340

docker-composer.yml

version: "3.9"
services:
  registry:
    image: "registry:2.8"
    restart: always
    container_name: registry
    ports:
      - "5000:5000"
    volumes:
      - './data:/var/lib/registry'
      - './config.yml:/etc/docker/registry/config.yml'
      - './auth:/auth'
    environment:
      - TZ=Asia/Shanghai
      - REGISTRY_STORAGE_DELETE_ENABLED= true
      - REGISTRY_AUTH=htpasswd
      - REGISTRY_AUTH_HTPASSWD_REALM=Registry_Realm
      - REGISTRY_AUTH_HTPASSWD_PATH=/auth/passwd

带密码查看远程仓库

* 查看远程仓库
curl -XGET -u username:password  https://xxx.xxxx.com/v2/_catalog
* 查看tag
curl -XGET -u username:password https://xxx.xxxx.com/v2/sxide/tags/list

docker pull/push使用

#使用账号登录仓库
docker login xxx.xxxx.com
#带密码登录
docker login  xxx.xxxx.com -u username -p password
docker login xxx.xxxx.com --username username --password password
* 用户权限会保存在 .docker/config.json中

#推送代码
docker push xxx.xxxx.com/nginx:1.21.5
#拉取代码
docker pull xxx.xxxx.com/nginx:1.21.5

#命令,退出登录
docker logout