转自:https://www.cnblogs.com/tangzz/p/11950126.html
1.sudo apt-get remove docker.io docker-engine
2.sudo apt-get update
3.$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg-agent \ software-properties-common
4.# 官方源 $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - # 中科大源
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # 清华源
$ curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 检查秘钥是否安装成功
$ sudo apt-key fingerprint 0EBFCD88
5.# 官方源 $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
# 中科大源 $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable"
# 清华源 $ sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable"
6.$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
# 检查是否安装完成
$ sudo docker run hello-world
7.$ sudo usermod -aG docker username
8.$ sudo mkdir -p /etc/docker $ sudo tee /etc/docker/daemon.json <<-‘EOF‘ { "registry-mirrors": [ "https://1nj0zren.mirror.aliyuncs.com", "https://docker.mirrors.ustc.edu.cn", "http://f1361db2.m.daocloud.io", "https://registry.docker-cn.com" ] } EOF
9.$ sudo systemctl daemon-reload
$ sudo systemctl restart docker