当前位置: 首页 > 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.dtcms.com/a/287119.html

相关文章:

  • 网络原理——TCP
  • 【学习记录】智能客服小桃(进度更新ing)
  • 张 关于大语言模型(LLM)置信度研究的经典与前沿论文 :温度缩放;语义熵;自一致性;事实与反思;检索增强;黑盒引导;
  • 软考 系统架构设计师系列知识点之杂项集萃(113)
  • LangGraph教程10:LangGraph ReAct应用
  • 基于Electron打包jar成Windows应用程序
  • 技术演进中的开发沉思-39 MFC系列:多重文件和多重视图
  • 安全事件响应分析--基础命令
  • 【52】MFC入门到精通——(CComboBox)下拉框选项顺序与初始化不一致,默认显示项也不一致
  • pytorch:tensorboard和transforms学习
  • HTML5中的自定义属性
  • Jenkins自动化部署.NET应用实战:Docker+私有仓库+SSH远程发布
  • mysql常用总结
  • EMC杂谈-001-基础知识
  • 【面试八股文】软件测试面试题汇总
  • [黑马头条]-项目整合对象存储服务MinIO
  • 百度网盘TV版1.21.0 |支持倍速播放,大屏云看片
  • CS231n-2017 Lecture2图像分类笔记
  • 工业企业与污染库匹配数据库(1998-2014年)
  • Letter Combination of a Phone Number
  • Redis原理之集群
  • windows内核研究(驱动开发之内核编程)
  • Qt控件实战详解:深入掌握输入输出与数据展示
  • Python MCP与Excel增强智能:构建下一代数据处理和自动化解决方案
  • SpringBoot 3.0 挥别 spring.factories,拥抱云原生新纪元
  • 人该怎样活着呢?55
  • 【RK3576】Android 14 驱动开发实战指南
  • uview-ui使用u-icon文字图标展示
  • 报错:升级gcc,centos
  • 数据库第五次作业