1. 由于Ubuntu里apt官方库里的docker版本可能比较低,因此先用下面的命令行卸载旧版本(如果有的话)
sudo apt-get remove docker docker-engine docker-ce docker.io
2. 更新apt包索引:
sudo apt-get update
3. 执行下列命令行,使apt可以通过HTTPS协议去使用存储库:
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
4. 添加Docker官方提供的GPG密钥: https://download.docker.com/linux/ubuntu/gpg
curl -fsSL https://download.docker.com/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]
这就说明秘钥添加成功,然后添加Stable版本的存储库
5. 设置stable存储库:https://download.docker.com/linux/ubuntu
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
最后再次更新apt包索引:
sudo apt-get update
6. 安装最新版本的docker-ce:
sudo apt-get install -y docker-ce
7.使用命令sudo docker version可以查看安装docker的版本:
sudo docker version
结果如下
Client: Docker Engine - Community
Version: 20.10.10
API version: 1.41
Go version: go1.16.9
Git commit: b485636
Built: Mon Oct 25 07:42:59 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.10
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: e2f740d
Built: Mon Oct 25 07:41:08 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.11
GitCommit: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
8.使用命令sudo docker run hello-world,能观察到从远程下载这个测试用的容器:Pulling from library/hello-world:
sudo docker run hello-world
结果如下
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
然后看到打印消息:Hello from Docker! 说明Docker安装成功。
网友评论