欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 房产 > 建筑 > ubuntu 20.04 安装 docker 后遇到的网络问题

ubuntu 20.04 安装 docker 后遇到的网络问题

2025/5/7 13:02:04 来源:https://blog.csdn.net/weixin_50960004/article/details/144144188  浏览:    关键词:ubuntu 20.04 安装 docker 后遇到的网络问题

问题

安装docker后,无法拉取hello-world镜像,:

$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

但我是挂的代理,从浏览器中可以访问docker的仓库

解决过程

curl -v https://registry-1.docker.io/v2/

输出不全,仅有4行,且卡住了,

检查代理是否配置正确:

echo $HTTP_PROXY
echo $HTTPS_PROXY

输出是空的,但我在开启科学上网时会自动修改这个变量,原因是大小写的问题,
在开启科学上网时,会设置:终端通过环境变量设置: export http_proxy=http://127.0.0.1:7890 && export https_proxy=http://127.0.0.1:7890

原因是 环境变量的大小写敏感性。您设置的是小写的 http_proxy 和 https_proxy,而 HTTP_PROXY 和 HTTPS_PROXY 是大写的变量名。

同时设置大写变量
为了兼容某些应用程序(例如 Docker Daemon 或其他工具),您可以同时设置大写和小写的代理变量:

export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

此时curl -v https://registry-1.docker.io/v2/输出正确,但拉取镜像仍出错:

$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

解决办法1

科学上网改为全局代理,可以实现 拉取镜像和 docker search XXX

在改全局代理之前,我还设置了这个,并不清楚有什么影响

确保 Docker Daemon 配置了正确的代理。如果您使用了代理,但未将其应用于 Docker Daemon,则 Docker 无法通过代理访问网络。
配置 Docker Daemon 的代理

创建或编辑代理配置文件:

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo nano /etc/systemd/system/docker.service.d/http-proxy.conf

添加以下内容(替换为您的代理地址和端口):

[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.1"

重启 Docker 服务:

bash

sudo systemctl daemon-reload
sudo systemctl restart docker

验证代理设置是否生效:


systemctl show --property=Environment docker

解决办法2

https://www.cnblogs.com/lqqgis/p/18276118
这个教程后面的镜像源改为国内的
可以实现拉取镜像,但 docker search xxx 这个搜索命令无法输出

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词