搭建本地镜像库docker registry

  1. 拉取基础镜像

    • 拉取 redis

    docker pull redis

    • 拉取 docker registry

    docker pull registry

  2. 创建本地存储路径

  • redis 持久存储路径

    mkdir /redisCache/

  • registry 持久存储路径

    mkdir /dockerRegistry/registry

  1. 或添加云端存储

  2. 启动 redis

    docker run --name dockerRedis -p 6379:6379 -v /redisCache:/data -d --restart=always redis:latest redis-server --appendonly yes --requirepass "XXXXXXXXXXX"
    
  3. 连接redis

    docker run -it --rm --link dockerRedis:redis redis redis-cli -h dockerRedis -p 6379 -a "xxxxxxxxxxxxxx"
    # redis server密码:xxxxxxxxxxxxxx
    
  4. 配置 registry

    service_conf/docker_registry_config.yaml

  5. 启动 registry

    docker run -d -p 5000:5000 -v /dockerRegistry/registry:/var/lib/registry  -e /dockerRegistry/config.yml --restart always --name MyRegistry registry  
    # 本地存储路径: /dockerRegistry/registry
    # 本地配置: /dockerRegistry/config.yml
    
  6. Copy an image from Docker Hub to our registry

    1. Pull the ubuntu:16.04 image from Docker Hub.

      docker pull ubuntu:18.04

    2. Tag the image as localhost:5000/my-ubuntu. This creates an additional tag for the existing image. When the first part of the tag is a hostname and port, Docker interprets this as the location of a registry, when pushing.

      docker tag ubuntu:18.04 localhost:5000/my-ubuntu

    3. Push the image to the local registry running at localhost:5000:

      docker push 219.133.167.42:5000/my-ubuntu

    4. Remove the locally-cached ubuntu:16.04 and localhost:5000/my-ubuntu images, so that you can test pulling the image from your registry. This does not remove the localhost:5000/my-ubuntu image from your registry.

      docker image remove ubuntu:18.04
      docker image remove localhost:5000/my-ubuntu
      
    5. Pull the localhost:5000/my-ubuntu image from your local registry.

      docker pull 219.133.167.42:5000/my-ubuntu

    注意再远端服务器使用该镜像库时需要以下配置

    vim /etc/docker/daemon.json
    # 添加镜像源
    { "insecure-registries":["http://xxx.xxx.xxx.xxx:5000"] }
    # 重启 docker
    systemctl restart docker 
    
  7. Stop a local registry

    docker container stop MyRegistry
    # or 
    docker container stop MyRegistry && docker container rm -v MyRegistry
    
  8. 查看镜像库列表

    curl -XGET http://219.133.167.42:5000/v2/_catalog

个人阿里镜像加速服务

"registry-mirrors":["https://xxxxxx.mirror.aliyuncs.com"]

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值