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

107 天前
 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

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

2700 次点击
所在节点    Docker
26 条回复
chaleaochexist
106 天前
1. wsl 配置镜像网络
2. 科学上网, 虚拟网卡模式

如果是代理模式, 那就走代理.
zaunist
106 天前
https://note.qidong.name/2020/05/docker-proxy/
楼主看下这篇文章吧,docker 在不同使用条件下的代理配置,根据你的信息来看,你只是想拉取镜像,那么我的建议是找个镜像站,添加到 daemon.json 里就行了,至于什么 NAT 、TUN 啥的,都不必折腾,最省事的办法就是找个镜像站。
gray0
106 天前
在 wsl2 中,使用主机的 clash 代理,在本地~/.zshrc 或 ~/.bashrc 加入如下内容:
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
export https_proxy="http://${hostip}:7890"
export http_proxy="http://${hostip}:7890"
szguan
106 天前
## .wslconfig 中:
```
networkingMode=mirrored
autoProxy=true
```

## wsl2 中 /etc/wsl.conf
```
[network]
generateResolvConf = false
```

## wsl2 中 /etc/resolv.conf
```
nameserver 8.8.8.8
```

## 添加代理设置:
sudo nano ~/.bashrc

```
# 使用主机地址( WSL2 镜像网络)
export hostip=127.0.0.1
export hostport=7890 (替换为主机代理端口)
# HTTP/HTTPS 代理(常用程序使用)
export http_proxy="http://${hostip}:${hostport}"
export https_proxy="http://${hostip}:${hostport}"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
# SOCKS5 代理(部分支持 SOCKS5 的工具可使用)
export all_proxy="socks5h://${hostip}:${hostport}"
export ALL_PROXY="$all_proxy"
# 排除内网和本地地址不走代理
export no_proxy="localhost.0.0.1,::1,*.local.*.*.168.*"
export NO_PROXY="$no_proxy"

# proxychains4 命令别名(适用于需要强制 SOCKS 的程序)
alias pwget="proxychains4 wget"
alias pcurl="proxychains4 curl"
```

## 使配置生效
`source ~/.bashrc`
zypdominate1
105 天前
@gray0 卧槽,大佬,你太牛逼了,来在深夜的感慨,本来都准备放弃了。感谢~

```
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:ec153840d1e635ac434fab5e377081f17e0e15afab27beb3f726c3265039cfff
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/
```
SeanChang
68 天前
@tt0411 赞~好用~

群主试试轩辕镜像 docker 加速~https://xuanyuan.cloud

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

https://ex.noerr.eu.org/t/1146433

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

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

© 2021 V2EX