
Debian 是一款开源、社区驱动的 Linux 发行版,以稳定性、安全性、自由软件理念为核心特色,是全球最具影响力的 Linux 发行版之一。其设计目标是提供一个通用、可靠且符合自由软件标准的操作系统,广泛应用于服务器、桌面、嵌入式设备等场景,也是 Ubuntu、Linux Mint 等热门发行版的基础上游项目。
下面将介绍如何在 Debian 中安装 Docker:
(1)查看当前 Debian 的版本信息
root@localhost:~# cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 13 (trixie)" NAME="Debian GNU/Linux" VERSION_ID="13" VERSION="13 (trixie)" VERSION_CODENAME=trixie DEBIAN_VERSION_FULL=13.0 ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
(2)彻底卸载系统中与 Docker 相关的所有冲突或旧版本组件
root@localhost:~# for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done Reading package lists... Done ... Package 'runc' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
(3)更新本地软件包索引缓存
root@localhost:~# sudo apt-get update Hit:1 http://security.debian.org/debian-security trixie-security InRelease ... N: See apt-secure(8) manpage for repository creation and user configuration details.
(4)以管理员权限在系统中安装 ca-certificates 和 curl 这两个软件包
root@localhost:~# sudo apt-get install ca-certificates curl Reading package lists... Done ... 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
(5)安全添加 Docker 官方软件源
# 创建 /etc/apt/keyrings 目录,权限设为 0755,用于存放软件源的 GPG 密钥 root@localhost:~# sudo install -m 0755 -d /etc/apt/keyrings # 从 Docker 官方服务器下载 GPG 公钥,保存到 /etc/apt/keyrings/docker.asc 文件中(-fsSL 表示静默模式、跟随重定向、显示错误) root@localhost:~# sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc # 修改 docker.asc 密钥文件的权限,确保所有用户都有读取权限(避免 APT 验证时权限不足) root@localhost:~# sudo chmod a+r /etc/apt/keyrings/docker.asc # 生成 Docker 官方软件源的配置信息,并写入 /etc/apt/sources.list.d/docker.list 文件: # - arch=$(dpkg --print-architecture):自动获取系统架构(如 amd64、arm64) # - signed-by=/etc/apt/keyrings/docker.asc:指定验证软件源的 GPG 密钥路径 # - $(. /etc/os-release && echo "$VERSION_CODENAME"):自动获取系统的版本代号(如 bookworm、bullseye) # - > /dev/null:屏蔽 tee 命令的输出,保持终端整洁 root@localhost:~# echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \ $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
(6)更新本地软件包索引缓存
root@localhost:~# sudo apt-get update Hit:1 http://ftp.debian.org/debian trixie-backports InRelease ... Reading package lists... Done
(7)安装 Docker 官方最新版的完整生态系统,包含了运行和管理容器所需的全部核心组件和插件。
root@localhost:~# sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin Reading package lists... Done ... Processing triggers for libc-bin (2.41-12) ...
(8)查看 Docker 服务的当前运行状态及相关信息
root@localhost:~# sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled) Active: active (running) since Thu 2025-10-23 15:59:42 CST; 1min 19s ago Invocation: fab47bac31b6445b9a87da27c0af0572 TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 4629 (dockerd) Tasks: 13 Memory: 21.5M (peak: 24.5M) CPU: 508ms CGroup: /system.slice/docker.service └─4629 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ... Oct 23 15:59:42 localhost systemd[1]: Started docker.service - Docker Application Container Engine.
(9)验证 Docker 环境是否正确安装并能正常运行,同时演示 Docker 容器的基本工作流程。注意,hello-world 是 Docker 环境的测试用例,用于快速验证安装是否成功。
root@localhost:~# sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 17eec7bbc9d7: Pull complete Digest: sha256:6dc565aa630927052111f823c303948cf83670a3903ffa3849f1488ab517f891 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
到这里,Docker 安装成功了……
参考地址:https://docs.docker.com/engine/install/debian/