Windows 11 wsl 中安装的Ubuntu-24.04 中装docker

Windows 11 wsl 中安装的Ubuntu-24.04 中装docker

1、前期准备


2、安装步骤

第一步:先清理失败的残留(若需要的话)

bash 复制代码
# 删除无效的密钥文件
sudo rm -f /usr/share/keyrings/docker-archive-keyring.gpg
# 删除可能残留的源文件
sudo rm -f /etc/apt/sources.list.d/docker.list

第二步:用阿里云国内源重新安装(彻底解决网络问题)

bash 复制代码
# 1. 安装依赖
sudo apt update && sudo apt install -y ca-certificates curl gnupg lsb-release

# 2. 下载阿里云 Docker GPG 密钥(国内可通)
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# 3. 添加阿里云 Docker 软件源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# 4. 更新源
sudo apt update

# 5. 安装 Docker 完整三件套
sudo apt install -y docker-ce docker-ce-cli containerd.io

# 6. 启动并设置开机自启
sudo systemctl enable docker
sudo systemctl start docker

# 7. 免 sudo 权限
sudo usermod -aG docker $USER

第三步:验证安装

关闭 Ubuntu 窗口,重新打开(让用户组权限生效)

执行测试命令

bash 复制代码
docker run hello-world

出现 Hello from Docker! 即安装成功

2、

配置镜像地址

bash 复制代码
# 先解锁 resolv.conf(如果之前加了锁)
sudo chattr -i /etc/resolv.conf

# 删除旧的阿里云配置,写入新的通用镜像源
sudo rm -f /etc/docker/daemon.json
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://docker.rainbond.cc",
        "https://docker.1panel.live",
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com"
    ],
    "dns": ["223.5.5.5", "114.114.114.114"],
    "log-driver": "json-file",
    "log-opts": {
        "max-file": "1",
        "max-size": "50m"
    }
}
EOF

现在必须按上面的方式配置,这里是个大坑,之前的配置方式不行了。阿里云在 2025 年前后逐步下线了个人免费的 Docker 镜像加速服务,现在个人用户再用旧的加速器地址,会直接返回 403 禁止访问

bash 复制代码
# 这种方式已不适用了
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://xxxxxx.mirror.aliyuncs.com"]
}
EOF

3、重启docker

bash 复制代码
# 重载配置、重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker

# 测试拉取镜像
docker run hello-world
相关推荐
天天进步20153 分钟前
UI-TARS 源码解析 #22:二次开发实战:用 UI-TARS 做一个简单的 Windows 自动操作 Agent
windows·ui
啊哈一半醒15 分钟前
Windows 虚拟机搭建 CentOS 全过程(2026 最新版 + 踩坑解决)
linux·windows·centos
new_zhou26 分钟前
C++ 项目 AI 协作指南(Windows / MSVC 环境)
c++·人工智能·windows
我是小灰灰吖2 小时前
Ubuntu 22.04 + Qt 6.9.3 应用程序打包与部署完整指南
qt·ubuntu
GlueNa2SiO34 小时前
06-Docker存储与数据持久化
笔记·学习·docker
爬楼的猪4 小时前
跟着AI Agent学powershell
windows·ai编程
笨鸟先飞,勤能补拙4 小时前
网络安全等级保护 2.0:从定级备案、建设整改到持续合规的系统指南
网络·人工智能·windows·安全·web安全·网络安全·github
一位正在转型AI全栈的前端工程师5 小时前
前端转全栈:从 502 到 200,我的第一个 Docker+Nginx+Node.js 项目
docker·容器
yagami_gagami5 小时前
2026平航杯内存取证(StarMem)
windows·网络安全
自律懒人5 小时前
AI 沙箱逃逸 4 连发:GPT-5.6 黑进 Hugging Face、Kimi K3 抄答案,5 步给本地 Agent 装围栏
ubuntu