WSL 中无法访问 registry-1.docker.io/v2/,没法用 docker 拉取 image,试了很多方法都不行,累了

67 天前
 zypdominate1

在 windows11 中安装了 WSL 2 ( Ubuntu ),安装了 docker 后,死活没法 pull image 。

docker-compose up
Pulling db (mysql:8.0)...
ERROR: Get "https://registry-1.docker.io/v2/": context deadline exceeded

尝试过的方法:

  1. 修改 /etc/docker/daemon.json ,添加阿里云镜像源
  2. 使用 ipv4
  3. 修改 /etc/resolv.conf ,使用 nameserver 8.8.8.8 nameserver 1.1.1.1

麻了,有没大佬知道应该怎么解决这个问题呀。

2280 次点击
所在节点    Docker
26 条回复
dcsuibian
67 天前
8820670
67 天前
op 是很久没有用 docker 了吗 dockerhub 以及大的镜像站都被墙很久了
zypdominate1
67 天前
@dcsuibian 还是不行,不知道是不是我配置的有问题,我是在自己个人电脑上使用的。代理的地址要怎么配置才好,对代理不太懂。
```
cat http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://192.168.1.100:8080" # HTTP 代理
Environment="HTTPS_PROXY=http://192.168.1.100:8080" # HTTPS 代理
Environment="NO_PROXY=localhost,127.0.0.1,10.0.0.0/8,.internal" # 直连的地址
mag@Mag:/etc/systemd/system/docker.service.d$ cd -
/home/mag/tools/mysql-docker

mag@Mag:~/tools/mysql-docker$ sudo systemctl daemon-reload
mag@Mag:~/tools/mysql-docker$ sudo systemctl restart docker

mag@Mag:~/tools/mysql-docker$ docker-compose up
Pulling db (mysql:8.0)...
ERROR: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp 192.168.1.100:8080: connect: no route to host


docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp 192.168.1.100:8080: connect: no route to host
```
capric
67 天前
代理要用 wsl 宿主的 ip ,不是 192 的 ip ,可以用 ip route show | grep -i default | awk '{ print $3}'获取,参照文档 https://learn.microsoft.com/en-us/windows/wsl/networking
zed1018
67 天前
代理如果是在 win 上,直接用 localhost+端口就行了,可以先用 nc 测试一下
dcsuibian
67 天前
@zypdominate1 如果你用的是 clash 的话,那端口一般是 789x 什么的。要开启允许局域网连接,
Lemonadeccc
67 天前
如果是在自己 win 上,梯子开 tun 就行
bigshawn
67 天前
建议搞了透明代理,省的配置这个配置那个。
zypdominate1
67 天前
@Lemonadeccc win 上的梯子开代理,在 wsl 中也没法 pull image 。总之,都试过了,累了
zypdominate1
67 天前
@capric 貌似不支持代理?

wsl -d Ubuntu hostname -I
wsl: 检测到 localhost 代理配置,但未镜像到 WSL 。NAT 模式下的 WSL 不支持 localhost 代理。
172.20.107.81 172.17.0.1 172.18.0.1
tt0411
67 天前
试试国内镜像加速吧, 网上有很多, 比如 https://cloud.tencent.com/developer/article/2485043
daisyfloor
67 天前
- wsl2 配置里网络改为 mirror 模式: networkingMode=mirrored
- windows 上代理软件使用 tun 模式: 并开启严格路由 strict-route: true , 且 tun 的 mtu 改为 1500

这样配置后,在可靠的 TUN 网络下,wsl2 自己(如 apt update 或者 curl )和 docker 引擎(如镜像拉取,容器网络请求)都可以正常无感知使用代理。
labubu
67 天前
v2rayn 开 tun 模式亲测可行
Xheldon
67 天前
你需要修改 wslconfig ,网上有教程,后两项关了就可
YaakovZiv
67 天前
Linux 系统使用 docker 可以直接白嫖免费的,谷歌搜索关键词"xuanyuan docker"或者"1ms docker"
hefish
67 天前
我是直接在路由器上开了个梯子。。。
如果是外面的服务器,国内的,就开个代理指向家里的梯子,如果是国外的就直接 docker pull
laminux29
67 天前
1. Docker 是原生于 Linux 的系统,不要在 Windows 上用 docker ,不然发生任何问题都不奇怪。推荐使用 Debian 12 系统。

2.请不要使用机场,机场是合租性质,不稳定。一定要买带有 CN2 线路优化的大厂海外 VPS ,比机场稳太多。

3.使用诸如 xShell 之类的 SSH 工具连接 VPS ,并启用 socks 隧道功能。然后去 github 搜 socks 转 http 的小程序,把 socks 隧道转换为 http 隧道。最后编辑 docker 的配置文件:
/etc/systemd/system/multi-user.target.wants/docker.service

在 [Service] 节点下加入:
Environment="HTTP_PROXY=http://socks 转 http 程序所在服务器的 IP:端口/"
Environment="HTTPS_PROXY=http://socks 转 http 程序所在服务器的 IP:端口/"
Environment="NO_PROXY=localhost,10.0.0.0/8,127.0.0.0/8,172.16.0.0/16,192.168.0.0/16"

最后
systemctl daemon-reload
systemctl restart docker
重启 docker 服务就行了。
triptipstop
67 天前
用 docker-desktop 很舒服 就是得把 扩展 插件 AI 什么的全关了 不然一升级就坑
SenLief
67 天前
docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp 192.168.1.100:8080: connect: no route to host

没有连上代理,建议直接宿主机 tun
fakecoder
67 天前
我是 wsl2 安装了 clash,op 可以试试...

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1146433

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX