---
# System prepended metadata

title: nydus使用dragonfly和https镜像仓库

---

# nydus使用dragonfly和https镜像仓库

## 1. Environment
- Https registry
测试可以直接使用如下镜像：
```shell=
https://hub.docker.com/repository/docker/gechangwei/python
```
- Dragonfly
本地启动dragonfly
```shell=
git clone https://github.com/dragonflyoss/Dragonfly2.git
cd Dragonfly2/deploy/docker-compose
sudo ./run.sh

sudo docker exec -it dfdaemon /bin/sh -c "tail -f /var/log/dragonfly/daemon/core.log"
```
- nerdctl
```shell=
wget https://github.com/containerd/nerdctl/releases/download/v0.22.2/nerdctl-full-0.22.2-linux-amd64.tar.gz
sudo tar -zxvf nerdctl-full-0.22.2-linux-amd64.tar.gz -C /usr/local

sudo systemctl enable --now containerd
sudo systemctl enable --now buildkit
sudo nerdctl version    # 需要使用sudo，不然会提示安装 rootless
```
## 2. nydus使用dragonfly
- Install nydus-snapshotter
```shell=
git clone https://github.com/containerd/nydus-snapshotter.git
cd nydus-snapshotter
make 
make install
```
- 配置containerd使用nydus-snapshotter
/etc/containerd/config.toml 添加内容：
```toml=
[proxy_plugins]
  [proxy_plugins.nydus]
    type = "snapshot"
    address = "/run/containerd-nydus/containerd-nydus-grpc.sock"

[plugins.cri]
  [plugins.cri.containerd]
    snapshotter = "nydus"
    disable_snapshot_annotations = false
```
重启containerd：
```shell!
sudo systemctl restart containerd
sudo ctr -a /run/containerd/containerd.sock plugin ls | grep nydus
```
- Nydusd 配置文件

配置文件放在/etc/nydus/config.json

```json=
{
  "device": {
    "backend": {
      "type": "registry",
      "config": {
        "host": "https 镜像中心地址",
        "auth": "XYZ=",    // 可以省略，由nydus-snapshotter获取
        "mirrors": [
          {
            "scheme": "http",
            "host": "127.0.0.1:65001", 
            "headers": {
              "X-Dragonfly-Registry": "https://index.docker.io"
            }
          },
          {
            "scheme": "http",
            "host": "dragonfly地址",
            "headers": {
              "X-Dragonfly-Registry": "https://index.docker.io"
            }
          }
          
        ],
        "scheme": "https",
        "timeout": 5,
        "connect_timeout": 5,
        "retry_limit": 2
      }
    },
    "cache": {
      "type": "blobcache",
      "config": {
        "work_dir": "cache"
      }
    }
  },
  "mode": "direct",
  "digest_validate": false,
  "iostats_files": false,
  "enable_xattr": true,
  "fs_prefetch": {
    "enable": true,
    "threads_count": 4
  }
}
```
- 构建nydus格式镜像
```shell=
sudo nydusify convert --nydus-image /usr/local/bin/nydus-image --source ubuntu --target https镜像中心/ubuntu-nydus
```
- Run nydusd with nydus-snapshotter
```shell=
git clone https://github.com/sctb512/image-service.git
cd image-service
git checkout mirror-dev

make fusedev-release
make install

sudo rm -rf /var/lib/nydus/cache/*

sudo systemctl enable nydus-snapshotter
sudo systemctl start nydus-snapshotter

sudo nerdctl --snapshotter nydus run --rm -it https镜像中心/ubuntu-nydus

# 使用已有nydus镜像
# sudo nerdctl --snapshotter nydus run --rm -it  https://hub.docker.com/repository/docker/gechangwei/python
```

## 3. 异常结果
- 请求dragonfly的时间为秒级
![](https://i.imgur.com/yJK9lCO.png)
