朱焱伟 发表于 2025-2-10 22:55:34

dget直接下载DockerHub镜像包

# dget直接下载DockerHub镜像包

早先时候,dockerhub各镜像站被封了,我没有说话;后来,greasyfork被封了,我没有说话;再后来。。脚本猫没封,哈哈,推荐大家使用脚本猫。

开个玩笑,不过dockerhub镜像站被封有时确实不方便。虽可以修改`/etc/docker/daemon.json`里的registry-mirrors,但随着镜像站一个个倒下,事情变得麻烦起来。如果不想使用个人账户阿里云的加速地址,也懒得给每台服务器设置代理,或许还是导出docker镜像,之后到处传文件比较方便。

(https://gitee.com/extrame/dget)这个工具可以`用于直接从docker hub中下载镜像包`,先在自己可以方便上网的Win电脑上下好镜像。


## clash 7890

首先,需要自己的Windows电脑方便上网:如果使用clash,其默认端口为7890,打开后,我们的目的是需要Powershell终端里也能方便上网。

`notepad $(echo $PROFILE)`会打开`Microsoft.PowerShell_profile.ps1`,我们可以设置一些常用命令:

```powershell
function clash-set-proxy {
    $env:http_proxy = "http://127.0.0.1:7890"
    $env:https_proxy = "http://127.0.0.1:7890"
    ::DefaultWebProxy = New-Object System.Net.WebProxy("http://127.0.0.1:7890")
    Write-Host "Proxy enabled: http://127.0.0.1:7890" -ForegroundColor Green
}

function clash-unproxy {
    $env:http_proxy = $null
    $env:https_proxy = $null
    ::DefaultWebProxy = $null
    Write-Host "Proxy disabled" -ForegroundColor Yellow
}

function clash-check-proxy {
    if ($env:http_proxy -or $env:https_proxy) {
      Write-Host "Current proxy settings:" -ForegroundColor Cyan
      Write-Host "HTTP Proxy: $env:http_proxy"
      Write-Host "HTTPS Proxy: $env:https_proxy"
    } else {
      Write-Host "No proxy is currently set." -ForegroundColor Cyan
    }
}
```

保存后,打开新的Powershell终端,那么新加的几个命令就生效了。

```powershell
curl.exe -vv http://www.google.com
```

先`clash-set-proxy`,再`curl.exe -vv http://www.google.com`,确认上网环境可以。(最后结束后可以`clash-unproxy`来关掉)

## dget.exe

然后可以下载dget.exe,然后放到`C:\Users\当前用户`目录下,这样方便下次打开powershell终端可以使用`dget.exe`

- https://gitee.com/extrame/dget/blob/master/bin/windows_amd64/dget.exe


```powershell
$url = "https://gitee.com/extrame/dget/raw/master/bin/windows_amd64/dget.exe"
$outputPath = "dget.exe"
Invoke-WebRequest -Uri $url -OutFile $outputPath
# 获取当前用户的目录路径
$userProfilePath = $env:USERPROFILE

# 定义目标路径(当前用户目录下的 dget.exe)
$destinationPath = Join-Path -Path $userProfilePath -ChildPath "dget.exe"

# 检查系统中是否已存在 dget.exe
if (-not (Test-Path -Path $destinationPath)) {
    # 如果不存在,则将下载的文件移动到当前用户目录
    Move-Item -Path $outputPath -Destination $destinationPath -Force
    Write-Host "dget.exe 已复制到: $destinationPath"
} else {
    # 如果已存在,则提示
    Write-Host "dget.exe 已存在于: $destinationPath"
    # 删除临时下载的文件
    Remove-Item -Path $outputPath -Force
}
```

## 用dget来下dockerhub上的镜像


以`van-nav`镜像为例,来在windows下尝试下载镜像:

```powershell
.\dget.exe mereith/van-nav:latest
```

可以得到`./tmp_mereith/van-nav_latest-img.tar.gz`,然后将其通过ftp上传到linux下,linux下就去load这个镜像

```bash
sudo docker load -i van-nav_latest-img.tar.gz
mkdir -p /usr/local/selfhosted/file/van-nav
sudo docker run -d --name tools --restart always -p 6412:6412 -v /usr/local/selfhosted/file/van-nav:/app/data mereith/van-nav:latest
# 浏览器访问 http://192.168.XXX.XXX:6412/
```

这样,就成功部署了一个简易的单文件的网页导航站,可以通过6412端口访问网页,通过dget避免了pull不下来的问题。


## 链接

- (https://gitee.com/extrame/dget) 用于直接从docker hub中下载镜像包
- (https://blog.csdn.net/baijiafan/article/details/129077647)
- (https://github.com/mereithhh/van-nav) 单文件部署的轻量导航站
- (https://zhuanlan.zhihu.com/p/17276972422)
页: [1]
查看完整版本: dget直接下载DockerHub镜像包