ubuntu 26.04安装指定版本的docker和docker compose

 

1.卸载系统自带旧docker,避免冲突
sudo apt remove -y docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc
sudo apt autoremove -y

 

2.添加Docker 官方 APT 源(Ubuntu26.04 标准方式)
# 安装依赖
sudo apt update
sudo apt install -y ca-certificates curl gnupg

 

# 创建密钥目录
sudo install -m 0755 -d /etc/apt/keyrings
# 导入GPG密钥
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

 

3.添加使用阿里云
vi /etc/apt/sources.list
编辑主源文件
vi /etc/apt/sources.list
找到第一行类似:
plaintext
deb cdrom:[Ubuntu 26.04 ...]/ resolute main restricted
在行首加 # 注释掉.

 

配置阿里云
rm -f /etc/apt/sources.list.d/docker.sources

tee /etc/apt/sources.list.d/docker.sources <<'EOF'
Types: deb
URIs: https://mirrors.aliyun.com/docker-ce/linux/ubuntu
Suites: noble
Components: stable
Architectures: amd64
Signed-By: /etc/apt/keyrings/docker.asc
EOF

 

查看都有那些版本
apt update
apt-cache madison docker-ce
apt-cache madison docker-compose-plugin

 

4.安装指定版本
DOCKER_VER="5:26.1.4-1~ubuntu.24.04~noble" ##这里对应 Docker version 26.1.4
COMPOSE_VER="2.27.1-1~ubuntu.24.04~noble" ##这里对应 Docker Compose version v2.27.1


5.安装指定版本
apt install -y docker-ce=${DOCKER_VER} docker-ce-cli=${DOCKER_VER} containerd.io docker-buildx-plugin docker-compose-plugin=${COMPOSE_VER}
apt-mark hold docker-ce docker-ce-cli docker-compose-plugin containerd.io docker-buildx-plugin
systemctl enable --now docker

 

posted @ 2026-07-28 11:23  slnngk  阅读(70)  评论(0)    收藏  举报