1.卸载旧版本的docker
sudo apt-get remove docker docker-engine docker.io containerd runc
2.更新apt包索引
sudo apt-get update
3.安装apt依赖包
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
4.添加docker的GPG密钥
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
5.配置可用的镜像 重要
打开文件
sudo vim /etc/docker/daemon.json
在文件中添加
{
"registry-mirrors": [
"https://docker.m.daocloud.io"
]
}
添加后先按esc退出insert,再按:wq保存并退出
6.安装docker
可能需要一段时间
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
7.测试docker是否能正常工作
sudo docker run hello-world
若正常应该为
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest
8.随后可以查看docker版本
sudo docker version
查看镜像
sudo docker images