1、卸载原有docker环境
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
2、安装docker相关的依赖项
先更新一下
sudo apt-get update
安装依赖项
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3、添加 Docker 的官方 GPG 密钥:
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
验证密钥是否添加成功
$ sudo apt-key fingerprint 0EBFCD88
#出现下面内容说明添加成功
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
4、为docker设置一个稳定版的仓库
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu/ $(lsb_release -cs) \
stable"
注:如果添加仓库的时候出现了某镜像源网站 404 not found问题,那么就在软件与更新中的其他软件中把对应的网站取消勾选,重新执行命令即可!
5、再次更新
sudo apt-get update
6、 添加国内下载源
# 创建docker目录,再使用 cd /etc/docker 进入
sudo mkdir -p /etc/docker# 进入docker目录,如果输出说没有此目录,就按上一个命令创建
cd /etc/docker/#创建 daemon.json 文件 如果熟悉vim 可以使用vi命令
sudo vim daemon.json# 复制下面的内容,wq退出编辑保存
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
7、安装最新版本的 Docker Engine-Community 和 containerd
注:执行这一步之前必须执行第六步否则会安装失败
sudo apt-get install docker-ce docker-ce-cli containerd.io
8、测试是否安装成功
执行 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
Hello from Docker! ###出现这个说明安装成功!!!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/