当前位置: 首页 > news >正文

windows wsl2-06-docker hello world

hello-world 例子

就像其他任何一门语言一样,我们来体验 docker 的 hello world

$ docker run hello-world

但是报错

:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp 208.101.60.87:443: i/o timeout.
See 'docker run --help'.

原因

网络问题,发现 WSL 中网络不通

$ curl -v https://registry-1.docker.io/v2/
*   Trying 199.59.149.202:443...
*   Trying 2001::9df0:232:443...
* Immediate connect fail for 2001::9df0:232: Network is unreachable
* connect to 199.59.149.202 port 443 failed: Connection timed out
* Failed to connect to registry-1.docker.io port 443 after 133350 ms: Connection timed out
* Closing connection 0
curl: (28) Failed to connect to registry-1.docker.io port 443 after 133350 ms: Connection timed out

解决办法

这和之前的 Docker 报错一致,问题根源在网络连通性,而不是链接本身。

1. 使用国内镜像加速(最快解决)

在 WSL 中执行:

sudo tee /etc/docker/daemon.json <<'EOF'
{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://registry.docker-cn.com"]
}
EOF

然后重启 Docker:

sudo systemctl restart docker  # 若你启用了 systemd
# 或
sudo service docker restart    # 若未启用 systemd

再试:

docker run hello-world

发现还是不行,依然报错

$ docker run 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'.

不过在 WSL 中 ping 一下百度,网络正常

$ ping baidu.com
PING baidu.com (182.61.244.181) 56(84) bytes of data.
64 bytes from 182.61.244.181 (182.61.244.181): icmp_seq=1 ttl=51 time=12.0 ms
64 bytes from 182.61.244.181 (182.61.244.181): icmp_seq=2 ttl=51 time=54.8 ms
64 bytes from 182.61.244.181 (182.61.244.181): icmp_seq=3 ttl=51 time=35.9 ms
64 bytes from 182.61.244.181 (182.61.244.181): icmp_seq=4 ttl=51 time=90.4 ms

确认配置+添加DNS解析

确认配置

$ cat  /etc/docker/daemon.json
{"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://registry.docker-cn.com"]
}

dns

$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
# nameserver 172.23.224.1
nameserver 114.114.114.114

可用 ip

dig @114.114.114.114 registry-1.docker.io 找到可用IP

结果很少,感觉很奇怪。

$ dig @114.114.114.114 registry-1.docker.io +short
168.143.162.58

修改 host 文件

echo "168.143.162.58 registry-1.docker.io" | sudo tee -a /etc/hosts

重启

$ sudo systemctl restart docker

确认

docker run hello-world

发现还是不行,真的麻烦。

http://www.lryc.cn/news/593401.html

相关文章:

  • windows wsl ubuntu 如何安装 open-jdk8
  • rustdesk客户端编译
  • NX二次开发常用函数坐标转化UF_MTX4_csys_to_csys和UF_MTX4_vec3_multipl
  • 【REACT18.x】creat-react-app在添加eslint时报错Environment key “jest/globals“ is unknown
  • 【橘子分布式】gRPC(编程篇-中)
  • Vue3生命周期函数
  • SQL基础操作指南:约束、表设计与复杂查询
  • Oracle RU19.28补丁发布,一键升级稳
  • 在摄像机视图中想像在普通 3D 视口里那样随意移动
  • 计算机网络1.1:计算机网络在信息时代的作用
  • 删除debian xdm自启动ibus的配置项
  • rust实现的快捷补全到剪贴板的实用工具
  • 汽车ECU控制器通信架构
  • 解决问题七大步骤
  • 论文reading学习记录4 - weekly - 视觉端到端开创-LOAM
  • [spring6: Advice Advisor Advised]-快速理解
  • Leetcode 05 java
  • Linux --进程信号
  • 本地部署开源的 AI 驱动的搜索引擎 Perplexica 并实现外部访问
  • FreeRTOS学习笔记之软件定时器
  • 访问 gitlab 跳转 0.0.0.0
  • 【主讲嘉宾揭幕】2025第二届机电一体化、机器人与控制系统国际会议(MRCS2025)
  • [MarkdownGithub] 使用块引用高亮显示“注意“和“警告“和其他注意方式的选项
  • 如何优雅调整Doris key顺序
  • HTTP与HTTPS技术细节及TLS密钥交换与证书校验全流程
  • springboot基础-demo
  • 【iOS】ZARA仿写
  • linux板远程操控——todesk
  • Matplotlib和Plotly知识点(Dash+Plotly分页展示)
  • Typecho博客评论无限滚动加载实现指南