ubuntu 20.04 安装最新版本 docker
一,更新系统包索引
sudo apt update
二,安装必要的依赖包
sudo apt install apt-transport-https ca-certificates curl software-properties-common
三,添加 Docker 官方 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
四,添加Docker官方APT仓库
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
五,更新包索引,并且安装Docker引擎
更新包索引,这一步可能出错,但是重试一次又可以了。
sudo apt update
安装Docker引擎,容器工具,插件
必须等上一步不报错了,再进行此步
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
配置镜像源,加速访问
否则,步骤七测试拉取可能失败
补:后来发现即使mirrors配置成功,但仍然走的是官方源,原因未知。
补2:实测vpn挂香港节点,能正常拉取官方源。
- 创建配置文件
sudo nano /etc/docker/daemon.json
- 添加镜像源
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://noohub.ru",
"https://huecker.io",
"https://dockerhub.timeweb.cloud",
"https://hub.rat.dev/",
"https://docker.1panel.live/",
"https://docker.nju.edu.cn",
"https://dockerproxy.com"
],
"dns" : [
"114.114.114.114",
"8.8.8.8"
]
}
ctrl o 保存 ctrl x 退出
- 重新加载,并且重启服务
sudo systemctl daemon-reload
sudo systemctl restart docker
这里我重启很多次,但是配置不奏效,最后将虚拟机重启,配置成功生效。建议重启虚拟机。
六,启动服务器并且设置开机自启
sudo systemctl start docker
sudo systemctl enable docker
七,验证能否正常使用
会返回版本信息
docker --version
注意若不是root用户,需要sudo,否则会报权限不足
sudo docker images
正常则会返回:
REPOSITORY TAG IMAGE ID CREATED SIZE
测试能否正常拉取
sudo docker run hello-world
正常则会返回:
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:ec153840d1e635ac434fab5e377081f17e0e15afab27beb3f726c3265039cfff
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/