Skip to content

在Ubuntu 22.04 LTS 进行Docker最新版本安装

卸载历史版本

shell
apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
apt-get remove docker docker-engine docker.io containerd runc
rm -rf /etc/docker && rm -rf /usr/libexec/docker && rm -rf /var/lib/docker && rm -rf /var/lib/containerd && rm -rf /etc/apt/keyrings
whereis docker # 确保没有和docker相关的文件

使用 Apt 存储库安装

shell
apt-get update && apt-get install ca-certificates curl gnupg install lsb-release apt-transport-https software-properties-common

install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

将存储库添加到 Apt 源

shell
echo \
  "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update

安装指定版本 Docker

shell
chmod a+r /etc/apt/keyrings/docker.gpg && apt-get update
apt-cache madison docker-ce | awk '{ print $3 }' # 查询存储库中可用的版本
VERSION_STRING=5:24.0.6-1~debian.11~bullseye # 指定版本号
apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

检查安装结果

shell
docker --version # 检查安装版本:Docker version 24.0.6, build ed223bc
docker info # 基本信息