当前位置: 首页 > 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.xdnf.cn/news/1148815.html

相关文章:

  • 1.初始化
  • Windows原生环境配置Claude Code MCP(通过JSON)
  • 【MySQL笔记】视图
  • Spring AI 项目实战(十九):Spring Boot + AI + Vue3 + OSS + DashScope 构建多模态视觉理解平台(附完整源码)
  • mac 配置svn
  • 医疗AI与融合数据库的整合:挑战、架构与未来展望(上)
  • xss-labs1-8题
  • 浏览器渲染原理——计算属性和布局过程常考内容
  • 基于单片机病床呼叫系统/床位呼叫系统
  • ChatGPT Agent深度解析:告别单纯问答,一个指令搞定复杂任务?
  • 目标检测中的标签分配算法总结
  • 2021 RoboCom 世界机器人开发者大赛-本科组(初赛)解题报告 | 珂学家
  • RS485转Profibus网关助力涡街液体流量计与300PLC高效通讯
  • Python高级数据类型:字典(Dictionary)
  • 模型的评估与选择
  • 基于springboot的考研互助小程序
  • 408数据结构强化(自用)
  • Java中缓存的使用浅讲
  • 【Linux驱动-快速回顾】简单了解一下PinCtrl子系统:设备树如何被接解析与匹配
  • 标准文件和系统文件I/O
  • CSS篇——第一章 六十五项关键技能(上篇)
  • 配置华为交换机接口链路聚合-支持服务器多网卡Bind
  • 解决Maven版本不兼容问题的终极方案
  • 定时器中BDTR死区时间和刹车功能配置
  • 低代码平台ToolJet实战总结
  • Flutter基础(前端教程①③-单例)
  • java内存图
  • 【Linux服务器】-MySQL数据库参数调优
  • Ubuntu 22.04.3 LTS 安装 MySQL
  • Kubernetes常用命令总结