创建服务

1.编辑docker-compose.yml文件

version: "3"
services:
  registry:
    image: registry
    container_name: registry
    privileged: true
    volumes:
      - ./htpasswd:/auth/htpasswd #步骤2创建
      - ./registry:/var/lib/registry
      - /etc/localtime:/etc/localtime
    ports:
      - 10020:5000
    environment:
      - REGISTRY_AUTH=htpasswd
      - REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd
      - REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm
      - REGISTRY_STORAGE_DELETE_ENABLED=true
    restart: always

2.创建htpasswd文件

生成账号密码:root 123456
docker run --entrypoint htpasswd registry:latest -Bbn root 123456  >> ./htpasswd

3.执行docker-compose up -d启动容器


客户端使用

1.编辑/etc/docker/daemon.json,添加ip白名单

{
    "insecure-registries": ["192.168.0.2:10020"]
}

2.执行systemctl restart docker重启容器

常用命令

docker login 192.168.0.2:10020 #登录容器
docker logout 192.168.0.2:10020 #退出登录
docker tag 66212d86b283 192.168.0.2:10020/redis:latest #新增tag
docker push 192.168.0.2:10020/redis:latest #推送镜像