参考
- https://www.sysgeek.cn/install-docker-ubuntu/ (主要参考)
- https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/ (清华镜像站)
- https://blog.csdn.net/dragonstrong/article/details/118915771 (ubuntu 设置代理,需要梯子开启局域网访问,并指定端口号)
- https://blog.csdn.net/sxzlc/article/details/105922314 (telnet 验证主机端口是否正常访问)
- https://blog.csdn.net/Fengdf666/article/details/140218342 (解决docker官方无法正常访问,切换docker下载为阿里源)
- https://juejin.cn/post/7135739035158315022
环境
软件/系统 | 版本 | 说明 |
---|---|---|
VMware | Workstation 16 Pro 16.2.4 build-20089737 | |
Ubuntu Server | Ubuntu Server 24.04 LTS | |
net-tools | 2.10-0.1ubuntu4 | 软件包 (查看虚拟机ip使用) |
nano | 7.2-2build1 | 软件包(编辑器) |
apt-transport-https | 2.7.14build2 | 软件包 |
curl | 8.5.0-2ubuntu10.3 | 软件包 |
docker-ce | 5:27.2.0-1 | 软件包 |
docker-ce-cli | 5:27.2.0-1 | 软件包 |
containerd.io | 1.7.21-1 | 软件包 |
docker-compose-plugin | 2.29.2-1 | 软件包 |
正文
-
设置软件源为国内源(此处使用清华源)
# 备份源 sudo cp /etc/apt/sources.list.d/ubuntu.sources /etc/apt/sources.list.d/ubuntu.sources.back # 编辑源 sudo nano /etc/apt/sources.list.d/ubuntu.sources
将下面的内容填充到
ubuntu.sources
Types: deb URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu Suites: noble noble-updates noble-backports Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 # Types: deb-src # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # Suites: noble noble-updates noble-backports # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换 Types: deb URIs: http://security.ubuntu.com/ubuntu/ Suites: noble-security Components: main restricted universe multiverse Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # Types: deb-src # URIs: http://security.ubuntu.com/ubuntu/ # Suites: noble-security # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # 预发布软件源,不建议启用 # Types: deb # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # Suites: noble-proposed # Components: main restricted universe multiverse # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg # # Types: deb-src # # URIs: https://mirrors.tuna.tsinghua.edu.cn/ubuntu # # Suites: noble-proposed # # Components: main restricted universe multiverse # # Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
-
更新软件包并安装必要软件
由于备份了
ubuntu.sources
为ubuntu.sources.back
所以后续执行 apt 相关命令时会提示N: Ignoring file 'ubuntu.sources.back' in directory '/etc/apt/sources.list.d/' as it has an invalid filename extension
,忽视即可。sudo apt update sudo apt install apt-transport-https curl
-
导入阿里云官方 GPG 密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
-
添加阿里云源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
-
更新源
sudo apt update
-
安装
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y