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

解决 WSL 中无法访问 registry-1.docker.io/v2/,无法用 docker 拉取 image

文章目录

    • 无法拉取docker镜像
    • 补充
      • 迁移 WSL 位置
      • Install Docker

无法拉取docker镜像

docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceededRun 'docker run --help' for more information

解决:

在 WSL 的 ~/.bashrc 加入如下内容:

export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
export https_proxy="http://${hostip}:7890"
export http_proxy="http://${hostip}:7890"

刷新:source ~/.bashrc

编辑 /etc/resolv.conf(该文件在WSL重启后会恢复默认配置)使用如下:

nameserver 8.8.8.8

保存后设置文件为不可变(防止被修改):

sudo chattr +i /etc/resolv.conf

同时宿主机器,使用 clash 开启虚拟网卡模式


补充

迁移 WSL 位置

将 WSL 从 C 盘迁移到 D 盘。

当前版本

>wsl --list --verboseNAME      STATE           VERSION
* Ubuntu    Running         2

关闭 wsl、注销、导出为归档文件

wsl --shutdown
wsl --export Ubuntu "D:\software\WSL\ubuntu_backup.tar"
wsl --unregister Ubuntu
# 注销原先在C盘的 Ubuntu WSL 实例,删除原始文件并释放 C 盘空间。

导入并启动

wsl --import Ubuntu "D:\software\WSL\Ubuntu" "D:\software\WSL\ubuntu_backup.tar" --version 2wsl --list --verbose
wsl

Install Docker

sudo apt update && sudo apt upgrade -y
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
sudo usermod -aG docker $USER
sudo service docker startdocker --version
docker run hello-world
sudo apt install docker-compose
docker-compose --version
http://www.dtcms.com/a/295854.html

相关文章:

  • 新能源电池厂自动化应用:Modbus TCP转DeviceNet实践
  • IDM下载失败全面排查指南
  • 医疗设备自动化升级:Modbus TCP与DeviceNet的协议协同实践
  • DPO:大语言模型偏好学习的高效方案
  • Python 程序设计讲义(15):Python 的数据运算——位运算
  • Opentrons 模块化平台与AI技术助力智能移液创新,赋能AAW™自动化工作站
  • 深入探索Amazon SQS:构建弹性微服务与无服务器应用的秘密武器
  • 如何在Ubuntu系统下创建桌面快捷方式
  • Vue 3 项目性能优化指南
  • rk3588开发板使用硬件编码处理视频
  • 如何在 Windows 上安装 MongoDB 及常见问题
  • AI总结视频以及谷歌浏览器插件安装步骤
  • RAGFlow:检索增强生成技术的高效实现与深度探索
  • Day02_C++编程
  • 基于U-Net的结冰检测系统实现
  • C11补充
  • SGLang + 分布式推理部署DeepSeek671B满血版
  • 数据结构-5(二叉树)
  • pytorch-geometric包(torch_scatter、torch_sparse、torch_cluster)
  • 服务器带宽具体是指什么意思?
  • PyTorch中神经网络的模型构建
  • 钉钉DingTalk完整版下载离线安装包2025
  • 【小董谈前端】【样式】 CSS与样式库:从实现工具到设计思维的跨越
  • ThinkPHP8集成RabbitMQ的完整案例实现
  • C# 方法执行超时策略
  • [Python] -进阶理解5- Python 模块与包的导入机制解析
  • uniapp中mp-html使用方法
  • 特定日志输出aop实现
  • day62-可观测性建设-全链路监控zabbix+grafana
  • Redis的事务和Lua之间的区别