ubuntu20.04安装docker27.2.1
时间: 2025-06-30 21:16:50 浏览: 15
### 安装指定版本的 Docker 27.2.1 在 Ubuntu 20.04 上
在 Ubuntu 20.04 系统上安装特定版本的 Docker(例如 **Docker CE 27.2.1**),可以通过以下步骤完成。此方法适用于在线环境,通过官方仓库精确选择版本进行安装。
---
#### 添加 Docker 官方仓库
首先,需要将 Docker 的官方仓库添加到系统中,并确保可以信任其 GPG 密钥。
```bash
# 安装必要的依赖包
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
# 添加 Docker 的官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
```
接着,将 Docker 的仓库地址写入源列表:
```bash
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
---
#### 更新软件包并查看可用版本
更新本地软件包索引,并查看 `docker-ce` 的可用版本信息:
```bash
sudo apt-get update
apt-cache policy docker-ce
```
此时可以看到类似如下的输出,其中包含多个版本号:
```
docker-ce:
Installed: (none)
Candidate: 5:27.3.1-1~ubuntu.20.04~focal
Version table:
5:27.3.1-1~ubuntu.20.04~focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:27.3.0-1~ubuntu.20.04~focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
5:27.2.1-1~ubuntu.20.04~focal 500
500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
```
---
#### 安装指定版本 Docker CE 27.2.1
使用 `apt-get install` 命令并指定版本号来安装所需的 Docker 版本:
```bash
sudo apt-get install -y docker-ce=5:27.2.1-1~ubuntu.20.04~focal docker-ce-cli=5:27.2.1-1~ubuntu.20.04~focal containerd.io
```
> 注意:如果未指定 `docker-ce-cli` 的版本,可能会导致版本不一致的问题[^2]。
---
#### 验证安装
安装完成后,验证 Docker 是否正常运行:
```bash
sudo systemctl status docker
```
也可以通过运行一个测试容器来确认:
```bash
sudo docker run hello-world
```
---
#### 锁定版本防止自动升级(可选)
为了避免系统更新时意外升级到其他版本,可以使用 `apt-mark hold` 命令锁定当前安装的 Docker 版本:
```bash
sudo apt-mark hold docker-ce docker-ce-cli containerd.io
```
这将防止这些包在后续的 `apt upgrade` 操作中被更新。
---
阅读全文
相关推荐















