【docker】拉取镜像时环境报错

作者: admin 分类: 技术 发布时间: 2024-12-14 20:53

解决Error Get “https://registry-1.docker.io/v2/”:环境报错问题~亲测有效

最近在使用ubuntu 20.04部署docker等程序服务发现使用docker 拉取镜像时环境报错 mysql Error Get “https://registry-1.docker.io/v2/”:环境报错问题 找了很多贴子
有人说之前的资源地址被墙了,可以使用更换成国内镜像源 和 添加代理地址的方式
经过我的不断尝试 找到此问题的解决方案
通过添加国内镜像代理 成功解决 已下是解决方案

1.进入 Docker 配置文件,通常位于 /etc/docker/daemon.json

sudo vi /etc/docker/daemon.json

添加以下内容

{
  "registry-mirrors":
    [
      "https://docker.m.daocloud.io/",
      "https://huecker.io/",
      "https://dockerhub.timeweb.cloud",
      "https://noohub.ru/",
      "https://dockerproxy.com",
      "https://docker.mirrors.ustc.edu.cn",
      "https://docker.nju.edu.cn",
      "https://xx4bwyg2.mirror.aliyuncs.com",
      "http://f1361db2.m.daocloud.io",
      "https://registry.docker-cn.com",
      "http://hub-mirror.c.163.com",
            "https://mirror.iscas.ac.cn",
      "https://docker.mirrors.ustc.edu.cn"
    ]
}

或者

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://vzt67ujg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

修改完成后,重启 Docker 服务:

sudo systemctl restart docker

这个镜像有些环境下可能在重新加载时,有报配置文件错误的情况,这种情况下,不要慌使用2分法 对以上镜像 分块加入到环境中,测试(我一同事就只添加了上面一半的镜像就解决了问题)

检查加速器是否生效

命令行执行 docker info 如果从结果中看到了如下内容,说明配置成功。

Registry Mirrors:
 [...]
 https://docker.m.daocloud.io

 

2.增加请求超时时间:可以尝试增加 Docker 的默认超时时间。例如在 WSL 的 Ubuntu 环境下,可以增加 Docker 的客户端超时时间

export DOCKER_CLIENT_TIMEOUT=120
export COMPOSE_HTTP_TIMEOUT=120

3.有时候 DNS 配置可能会导致网络请求超时。可以尝试修改 /etc/resolv.conf 文件,将 DNS 服务器改为公共 DNS,比如

sudo vi /etc/resolv.conf

删掉默认的nameserver地址在后面增加

nameserver 8.8.8.8
nameserver 8.8.4.4

重新加载

systemctl restart systemd-resolved.service

4.重新安装或更新 Docker:可能是由 Docker 的安装版本引起的。可以尝试更新 Docker

sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io

最后大功告成

【docker】拉取镜像时环境报错

后续我这边在服务器上装了GPU支持,然后配置文件有所变化如下,格式是这样哈

{
    "dns": ["8.8.8.8", "8.8.4.4"],
    "registry-mirrors": [
        "https://docker.m.daocloud.io/",
        "https://huecker.io/",
        "https://dockerhub.timeweb.cloud",
        "https://noohub.ru/",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn",
        "https://xx4bwyg2.mirror.aliyuncs.com",
        "http://f1361db2.m.daocloud.io",
        "https://registry.docker-cn.com",
        "http://hub-mirror.c.163.com"
    ],
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    }
}

完了之后 配置重新加载

sudo systemctl daemon-reload

docker 重新启动

sudo systemctl restart docker

大功告成!

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

标签云
站点地图 Sitemap
申请 友情链接
网站运行