第一步:卸载已将安装的docker
apt-get remove docker docker-engine docker-ce docker.io -y
第二步:安装前准备
1、更新索引包
2、添加阿里的 Docker 镜像仓库证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/aliyun-docker.gpg
如果 Ubuntu 22.04 还用 apt-key add 的方式添加证书在同步仓库信息时会有以下 warning:
Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
3、添加仓库
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/aliyun-docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
4. 更新索引包
第三步 安装指定的docker版本
1、列出可用版本
apt-cache madison docker-ce
2、选择一个版本来安装
apt-get install docker-ce=<VERSION>
比如:
apt-get install docker-ce=5:20.10.24~3-0~ubuntu-jammy -y
3、查看是否安装正常
sudo systemctl start docker
docker info