Linux(Debian)安装Docker和Docker Compose指南
安装方法:
1. 创建APT 软件源的密钥文件
sudo mkdir -p /etc/apt/keyrings
2. 下载并添加 Docker 的 GPG 公钥
# 清华大学镜像源
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
3. 获取你的 Debian 版本代号
lsb_release -cs
# 可能的输出:
# bookworm(Debian 12)
# bullseye(Debian 11)
# buster(Debian 10)
4. 编辑源列表文件
# 使用你获取的版本代号替换下面的 <DEBIAN_VERSION>:
echo \
"deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
<DEBIAN_VERSION> stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# 示例 bookworm(debian12):
echo \
"deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
bookworm stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5. 更新 APT 包索引
sudo apt update
6. 安装docker
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
7. (可选)设置docker开机自启动
sudo systemctl enable docker
验证安装
# docker
docker version
# docker compose
docker compose version
Linux(Debian)安装Docker和Docker Compose指南
https://hret.cloud/archives/linux-debian-docker