卸载旧版本
sudo apt-get remove docker docker-engine docker.io containerd runc
若卸载成功则继续删除残留文件
sudo rm -rf /var/lib/docker/
安装依赖
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg
将ubuntu 镜像源替换为阿里的ubuntu镜像源
将 /etc/apt/sources.list 文件中的内容替换为 阿里源地址
sudo vim /etc/apt/sources.list
将以下内容复制进入
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
添加 阿里镜docker像源的密匙
wget http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg
sudo apt-key add gpg
由于阿里镜像源地址 已经包含了docker 的镜像源地址所以没必要像网上其他教程那样向sources.list添加 docker镜像软件源地址:
deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu focal
stable
直接安装docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
验证安装
sudo docker run hello-world
systemctl status docker
docker 正常运行 hello word 且服务状态如上图即表示安装成功