在腾讯云的 Debian 系统上安装 Docker,可以按照以下步骤进行操作。这里以 Debian 10/11/12 为例。
✅ 步骤 1:更新系统包
sudo apt update && sudo apt upgrade -y
✅ 步骤 2:安装必要的依赖包
这些包允许 apt 使用 HTTPS 拉取仓库:
sudo apt install -y
ca-certificates
curl
gnupg
lsb-release
software-properties-common
✅ 步骤 3:添加 Docker 的官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
💡 注意:Docker 官方推荐使用签名的仓库方式来确保安全。
✅ 步骤 4:添加 Docker APT 仓库
根据你的 Debian 版本(如 bookworm、bullseye 等),添加仓库:
先查看你的 Debian 版本代号:
lsb_release -cs
输出可能是 bookworm(Debian 12)、bullseye(Debian 11)或 buster(Debian 10)。
然后运行(将 <codename> 替换为实际输出):
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
✅ 步骤 5:更新 APT 包索引
sudo apt update
✅ 步骤 6:安装 Docker Engine
sudo apt install -y docker-ce docker-ce-cli containerd.io
这会安装最新版本的 Docker 社区版(Docker CE)。
✅ 步骤 7:验证安装是否成功
sudo docker --version
你应该看到类似输出:
Docker version 24.0.7, build ...
测试运行一个容器:
sudo docker run hello-world
如果看到欢迎信息,说明 Docker 安装成功。
✅ (可选)配置非 root 用户使用 Docker
避免每次使用 sudo,可以将当前用户加入 docker 组:
sudo usermod -aG docker $USER
⚠️ 执行后需要 重新登录 或重启 shell 才能生效。
验证:
docker run hello-world
(此时无需 sudo)
✅ (可选)设置 Docker 开机自启
sudo systemctl enable docker
sudo systemctl start docker
🛑 常见问题
❌ 报错:E: Package 'docker-ce' has no installation candidate
- 检查你的 Debian 版本是否被 Docker 支持。
- 确认
sources.list.d/docker.list中的发行版名称正确(如bookworm而不是sid)。 - 可尝试手动指定架构和版本安装。
✅ 推荐:使用腾讯云镜像提速(提升拉取速度)
编辑或创建 daemon 配置文件:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://mirror.ccs.tencentyun.com"
]
}
EOF
腾讯云提供专属镜像提速地址:
https://mirror.ccs.tencentyun.com(需登录腾讯云控制台确认是否仍有效)
重启 Docker 生效:
sudo systemctl restart docker
✅ 至此,Docker 已成功在腾讯云的 Debian 系统上安装并配置完成!
如有需要,还可以继续安装 docker-compose:
sudo apt install -y docker-compose
或从 GitHub 下载最新版。
如需帮助判断系统版本或排查错误,请贴出你的 lsb_release -a 和错误信息。
云小栈