由于不建议用root用户安装Docker,新安装的系统没有sudo,安装sudo首先要更新软件包列表。
1、切换到root用户,编辑/etc/apt/sources.list文件
Bash / Shell
nano /etc/apt/sources.list
2、配置国内镜像源,我用的是兰州大学的镜像源。
Bash / Shell
deb http://mirror.lzu.edu.cn/debian/ trixie main non-free-firmware
deb-src http://mirror.lzu.edu.cn/debian/ trixie main non-free-firmware
deb https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware
deb-src https://mirrors.aliyun.com/debian-security trixie-security main contrib non-free non-free-firmware
deb http://mirror.lzu.edu.cn/debian/ trixie-updates main non-free-firmware
deb-src http://mirror.lzu.edu.cn/debian/ trixie-updates main non-free-firmware
3、更新软件包列表,安装sudo
Bash / Shell
apt update
apt install sudo
4、编辑/ etc/sudoers 文件,在文件末尾添加下面代码,把maizi换成你的用户名,给普通用户sudo权限
Bash / Shell
maizi ALL=(ALL:ALL) NOPASSWD:ALL
5、切换到普通用户,使用一键安装脚本安装Docker和Docker Compose
Bash / Shell
bash <(wget -qO- https://xuanyuan.cloud/docker.sh)
Typescript
脚本特性与优势
✅ 支持 13 种主流发行版:openEuler (欧拉)、OpenCloudOS、Anolis OS (龙蜥)、Alinux (阿里云)、Kylin Linux (银河麒麟)、Fedora、Rocky Linux、AlmaLinux、Ubuntu、Debian、CentOS、RHEL、Oracle Linux
✅ 国产操作系统完整支持:深度适配国产操作系统(openEuler、Anolis OS、OpenCloudOS、Alinux、Kylin Linux),支持版本自动识别和最优配置
✅ 多镜像源智能切换:内置阿里云、腾讯云、华为云、中科大、清华等 6+ 国内镜像源,自动检测并选择最快源
✅ 老版本系统特殊处理:支持 Ubuntu 16.04、Debian 9/10 等已过期系统,自动配置兼容的安装方案
✅ 双重安装保障:包管理器安装失败时自动切换到二进制安装,确保安装成功率
✅ ARM 架构完整支持:支持 ARM 64位(aarch64)架构,包括鲲鹏920、飞腾等国产处理器,自动检测架构并下载对应版本
✅ macOS/Windows 友好提示:自动检测 macOS 和 Windows 系统,提供适合的 Docker Desktop 安装指引
脚本已在GitHub开源

