【WSL】Ubuntu 24.04 安装配置docker
继上一篇文章:【WSL】Ubuntu 22.04 安装配置docker
这次我在新搭建的台式机安装的WSL上,也安装一个docker
,因为最近要开发TTS
相关的东西。
参考
清华大学镜像站的这篇文章基本涵盖了所有的操作步骤,照着做就行了:Docker CE 软件仓库
安装
我的WSL版本:
WSL 版本: 2.3.26.0
内核版本: 5.15.167.4-1
WSLg 版本: 1.0.65
MSRDC 版本: 1.2.5620
Direct3D 版本: 1.611.1-81528511
DXCore 版本: 10.0.26100.1-240331-1435.ge-release
Windows 版本: 10.0.26100.2605
ubuntu版本:
Ubuntu 24.04 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64)
使用lsb_release -a
查看版本代号:
Distributor ID: Ubuntu
Description: Ubuntu 24.04 LTS
Release: 24.04
Codename: noble
一开始整了一个乌龙,我所在的地方连接中科大镜像失败,所以不得不转投清华的镜像:
Err:1 https://mirrors.ustc.edu.cn/ubuntu oracular/main amd64 libgpg-error-l10n all 1.50-4
Cannot initiate the connection to mirrors.ustc.edu.cn:443 (2001:da8:d800:95::110). - connect (101: Network is unreachable) Could not connect to mirrors.ustc.edu.cn:443 (202.38.95.110), connection timed out
Err:2 https://mirrors.ustc.edu.cn/ubuntu oracular/main amd64 libgpg-error0 amd64 1.50-4
Cannot initiate the connection to mirrors.ustc.edu.cn:443 (2001:da8:d800:95::110). - connect (101: Network is unreachable)
Err:3 https://mirrors.ustc.edu.cn/ubuntu oracular/main amd64 libgcrypt20 amd64 1.11.0-6
Cannot initiate the connection to mirrors.ustc.edu.cn:443 (2001:da8:d800:95::110). - connect (101: Network is unreachable)
Err:4 https://mirrors.ustc.edu.cn/ubuntu oracular/main amd64 libapt-pkg6.0t64 amd64 2.9.8
Cannot initiate the connection to mirrors.ustc.edu.cn:443 (2001:da8:d800:95::110). - connect (101: Network is unreachable)
Err:5 https://mirrors.ustc.edu.cn/ubuntu oracular/main amd64 apt amd64 2.9.8
Cannot initiate the connection to mirrors.ustc.edu.cn:443 (2001:da8:d800:95::110). - connect (101: Network is unreachable)
大概报一堆类似这样的错误。
然后实测即使是24.04
的ubuntu,依然可以用老方法修改镜像,也就是改/etc/apt/sources.list
,替换成下面的就行了,记得备份(另外修改文件需要sudo,VS Code改不了,sudo code
也不行,不清楚为什么)
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-backports main restricted universe multiverse
# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ noble-proposed main restricted universe multiverse
WSL默认登录的用户不是root
,所以下面的操作都是带sudo
的。
如果你过去安装过 docker,先删掉:
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
首先安装依赖:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
信任 Docker 的 GPG 公钥并添加仓库:
发行版
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
这一步卡了我很久,如果你也出现下面的报错:
W: GPG error: https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu noble InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu noble InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
这说明清华镜像的docker公钥在你电脑上没有写入成功,我当时的解决办法是:
- 切换到
/etc/apt/sources.list.d
下,删除docker.list
- 切换到
/etc/apt/keyrings
下,删除docker.asc
和docker.gpg
- 重新执行上面的四步即可。
最后安装
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
测试
官方文档说可以通过下面这行运行一个容器看看docker效果:
sudo 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'.