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
相关推荐
小羊没烦恼!3 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
rockmelodies3 天前
# Windows Server2008 R2 Standard(SP1镜像U盘)重置本地管理员密码【完整详细步骤】
windows·密码破解
分布式存储与RustFS3 天前
MinIO 官方 Docker 镜像被移除:依赖它的项目该怎么办
docker·云原生·devops·对象存储·minio·分布式存储
玉&心3 天前
通过Arthas在线诊断K8S中的内存及JVM等使用情况
docker·k8s·arthas
xing-xing3 天前
Docker容器中Nginx站点根目录网页配置访问
nginx·docker
guo_wen_qiang3 天前
上传本地镜像到harbor中
docker·容器·持续部署
羑悻的小杀马特3 天前
Dockerfile 全景指南:从入门编写dockerfile到生产环境镜像优化实战,一步步带你从啃透制作指令到镜像制作落地!
docker·dockerfile·镜像制作
BianHuanShiZhe3 天前
docker常见命令
docker
正经教主3 天前
【FDE系列】阶段2:Day 43:Docker Compose — 多容器一键编排
人工智能·docker·fde
zhangrelay3 天前
《机器人控制器设计与编程》课程习题资料-2026
linux·笔记·学习·ubuntu