为Dragonfly配置私有仓库

本文档详细介绍了如何为Dragonfly配置私有仓库,包括部署SuperNode节点、配置Client节点,涉及设置supernode IP、创建dfclient容器、修改docker daemon配置、生成私有仓库认证及重启服务。通过这些步骤,确保能够成功从私有仓库拉取镜像。

为Dragonfly配置私有仓库

环境

OS: Centos 7
Docker version
	Client:
     Version:           18.06.1-ce
     API version:       1.38
     Go version:        go1.10.3
     Git commit:        e68fc7a
     Built:             Tue Aug 21 17:23:03 2018
     OS/Arch:           linux/amd64
     Experimental:      false

    Server:
     Engine:
      Version:          18.06.1-ce
      API version:      1.38 (minimum version 1.12)
      Go version:       go1.10.3
      Git commit:       e68fc7a
      Built:            Tue Aug 21 17:25:29 2018
      OS/Arch:          linux/amd64
      Experimental:     false

部署SuperNode节点

假设有4个节点的集群,节点IP分别为:

192.168.108.10 # superNode
192.168.108.11 # client 1
192.168.108.12 # client 2
192.168.108.13 # private registry

其中,192.168.108.10 作为 SuperNode 节点,192.168.108.13 是私有仓库的IP,其他2个节点作为Client节点。

首先部署SuperNode ,登录SuperNode 执行如下命令:

docker run -d --name supernode --restart=always -p 8001:8001 -p 8002:8002 \
	-v /home/admin/supernode:/home/admin/supernode \
	dragonflyoss/supernode:latest --download-port=8001

其中,参数Dsupernode.advertiseIp 用于指定supernode 节点IP

部署Client节点

部署Client节点步骤稍微多一些,在各个Client节点上执行下面操作即可。

1 . 为client配置supernode节点IP

mkdir /etc/dragonfly && cat <<EOD > /etc/dragonfly/dfget.yml
nodes:
    - 192.168.108.10
EOD

其中, 192.168.108.10 是supernode节点IP

2. 创建dfclient容器

docker run -d --name dfclient \
    --restart=always \
    -p 65001:65001 \
    -v /etc/dragonfly:/etc/dragonfly \
    -v $HOME/.small-dragonfly:/root/.small-dragonfly \
    dragonflyoss/dfclient:1.0.2 --registry http://192.168.108.13:5000 \
    --node 192.168.108.10 \
    --ratelimit 100M

其中,node 指定 SuperNode 节点IP;ratelimit 指定client节点的带宽限制,这里设置为100MB,默认是20MB;registry 指定私有仓库地址。

如果在启动Client时候报如下错误:

docker: Error response from daemon: driver failed programming external connectivity on endpoint dfclient (891bbe1add069cf7fe034f0cf8a7792ca6c5564bf4962cc6be7fc1dc40541f21):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 65001 -j DNAT --to-destination 172.17.0.2:65001 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)).

可用下面的方法解决

iptables -t filter -F && iptables -t filter -X && systemctl restart docker

先清除filter表中所有规则并删除filter表,最后再重启daemon

3. 配置docker daemon

cat <<EOD > /etc/docker/daemon.json
{
	"registry-mirrors": ["http://127.0.0.1:65001"],
	"insecure-registries" : ["192.168.108.13:5000"]
}
EOD

其中,registry-mirrors 用于镜像加速;insecure-registries 为私有仓库添加信任

4. 生成私有仓库认证

docker login -u name --password pwd 192.168.108.13:5000

其中,name 是私有仓库的用户名,pwd 是私有仓库密码,如果私有仓库没有配置用户名、密码,可以把它们分别填入admin123456 。执行完上面的操作,会在/root/.docker/config.json 生成私有仓库认证,如下所示:

{
        "auths": {
                "192.168.108.13:5000": {
                        "auth": "xxxxxxxxxx"
                }
        },
        "HttpHeaders": {
                "User-Agent": "Docker-Client/18.06.1-ce (linux)"
        }
}

其中,"auth": "xxxxxxxxxx" 字段就是私有仓库认证,需要记住xxxxxxxxxx 后面会用到。

执行完上面操作,再执行如下操作:

docker login -u 192.168.108.13:5000 --password local_pwd  http://127.0.0.1:65001

其中,local_pwd 是上面生成的认证信息,即需要记住的字段xxxxxxxxxx

5. 重启docker daemon

systemctl restart docker.service

测试

dragonfly拉取镜像操作和docker拉取镜像操作一样,如何从私有仓库拉取只需要加上127.0.0.1:65001 的前缀即可。

下面测试从私有仓库拉取golang 镜像

(base) [root@h12 overlay2]# docker pull 127.0.0.1:65001/golang
Using default tag: latest
latest: Pulling from golang
57df1a1f1ad8: Pull complete
71e126169501: Pull complete
1af28a55c3f3: Pull complete
03f1c9932170: Pull complete
f4773b341423: Pull complete
fb320882041b: Pull complete
24b0ad6f9416: Pull complete
Digest: sha256:0978cc067eb3f53901c00b70a024f182baa371bdfe7f35f3d64e56cab2471c4d
Status: Downloaded newer image for 127.0.0.1:65001/golang:latest
127.0.0.1:65001/golang:latest
(base) [root@h12 overlay2]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
127.0.0.1:65001/golang   latest              05c8f6d2538a        3 months ago        839MB
dragonflyoss/dfclient    1.0.2               3e0302d04abd        7 months ago        46.6MB

可以看到确实是拉取下来了。

执行下面命令

docker exec dfclient grep 'downloading piece' /root/.small-dragonfly/logs/dfclient.log

如果输出类似如下,则证明是用Dragonfly拉取的

2020-12-20 08:48:41.858 INFO sign:252-1608454119.090 : downloading piece:{"taskID":"8491e3138f5999110ba07953af32f4f78b1609caab45c38f55e2c1d9acb727ce","superNode":"192.168.108.10:8002","dstCid":"cdnnode:172.17.0.2~8491e3138f5999110ba07953af32f4f78b1609caab45c38f55e2c1d9acb727ce","range":"117440512-121634815","result":503,"status":701,"pieceSize":4194304,"pieceNum":28}

参考文献

https://d7y.io/en-us/docs/faq.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值