• 搭建docker镜像仓库


    拉取镜像仓库镜像

    docker pull registry
    
    • 1

    启动镜像仓库

    docker run -d -p 5000:5000 --restart=always --name registry registry
    
    • 1

    这将使用官方的 registry 镜像来启动私有仓库。默认情况下,仓库会被创建在容器的 /var/lib/registry 目录下。你可以通过 -v 参数来将镜像文件存放在本地的指定路径。例如下面的例子将上传的镜像放到本地的 /opt/data/registry 目录

    $ docker run -d \
        -p 5000:5000 \
        -v /opt/data/registry:/var/lib/registry \
        registry
    
    • 1
    • 2
    • 3
    • 4

    在私有仓库上传、搜索、下载

    创建好私有仓库后,就可以使用```docker tag来标记一个镜像,然后推送它到仓库。例如私有仓库地址为127.0.0.1:5000`
    先在本地查看已有的镜像

    $ docker image ls
    REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    ubuntu                            latest              ba5877dc9bec        6 weeks ago         192.7 MB
    
    • 1
    • 2
    • 3

    使用 docker tagubuntu:latest 这个镜像标记为 127.0.0.1:5000/ubuntu:latest
    格式为 docker tag IMAGE[:TAG] [REGISTRY_HOST[:REGISTRY_PORT]/]REPOSITORY[:TAG]

    $ docker tag ubuntu:latest 127.0.0.1:5000/ubuntu:latest
    $ docker image ls
    REPOSITORY                        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    ubuntu                            latest              ba5877dc9bec        6 weeks ago         192.7 MB
    127.0.0.1:5000/ubuntu:latest      latest              ba5877dc9bec        6 weeks ago         192.7 MB
    
    • 1
    • 2
    • 3
    • 4
    • 5

    使用 docker push 上传标记的镜像

    $ docker push 127.0.0.1:5000/ubuntu:latest
    The push refers to repository [127.0.0.1:5000/ubuntu]
    373a30c24545: Pushed
    a9148f5200b0: Pushed
    cdd3de0940ab: Pushed
    fc56279bbb33: Pushed
    b38367233d37: Pushed
    2aebd096e0e2: Pushed
    latest: digest: sha256:fe4277621f10b5026266932ddf760f5a756d2facd505a94d2da12f4f52f71f5a size: 1568
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    curl查看仓库中的镜像

    $ curl 127.0.0.1:5000/v2/_catalog
    {"repositories":["ubuntu"]}
    
    • 1
    • 2

    这里可以看到 {"repositories":["ubuntu"]},表明镜像已经被成功上传了。
    先删除已有镜像,再尝试从私有仓库中下载这个镜像

    $ docker image rm 127.0.0.1:5000/ubuntu:latest
    
    $ docker pull 127.0.0.1:5000/ubuntu:latest
    Pulling repository 127.0.0.1:5000/ubuntu:latest
    ba5877dc9bec: Download complete
    511136ea3c5a: Download complete
    9bad880da3d2: Download complete
    25f11f5fb0cb: Download complete
    ebc34468f71d: Download complete
    2318d26665ef: Download complete
    
    $ docker image ls
    REPOSITORY                         TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
    127.0.0.1:5000/ubuntu:latest       latest              ba5877dc9bec        6 weeks ago         192.7 MB
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    配置非https仓库地址

    如果你不想使用 127.0.0.1:5000 作为仓库地址,比如想让本网段的其他主机也能把镜像推送到私有仓库。你就得把例如 192.168.199.100:5000 这样的内网地址作为私有仓库地址,这时你会发现无法成功推送镜像。
    这是因为 Docker 默认不允许非 HTTPS 方式推送镜像。我们可以通过 Docker 的配置选项来取消这个限制

    {
      "registry-mirror": [
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com"
      ],
      "insecure-registries": [
        "192.168.199.100:5000"
      ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    私有仓库高级配置

    https://yeasy.gitbook.io/docker_practice/repository/registry_auth

    k8s搭建私有仓库

    使用这个helm https://github.com/lhzzz/charts/tree/master/stable/docker-registry

    • 装之前记得修改这里的host为自己的域名

    在这里插入图片描述

    helm install docker-registry -n registry .
    
    • 1
    • 然后修改/etc/hosts,加上这个域名registry.sakura.com
    • 然后在修改/etc/docker/daemon.json,加入如下这行

    在这里插入图片描述

  • 相关阅读:
    如何成为一个正经的 Microsoft 365 开发者
    一张图进阶 RocketMQ - 通信机制
    猿创征文|我毕业了一个月,却给了我过了一年的感觉
    详解PHP代码执行漏洞--无字母shell
    【深入浅出C#】章节10: 最佳实践和性能优化:内存管理和资源释放
    24.Gateway 断言工厂Predicate的使用(springcloud)
    Docker相关命令
    java计算机毕业设计ssm+Java EE陕西农产品网络交易平台-农产品和特产商城(源码+系统+mysql数据库+Lw文档)
    如何使用Java获取当前时间戳
    linux安装scrcpy最新版本
  • 原文地址:https://blog.csdn.net/Canger_/article/details/125490983