安装前准备
- 查看自己的操作系统
# 命令行输入,查看ubuntu 内核版本
$ uname -a
Linux instance 4.15.0-66-generic
#75-Ubuntu SMP Tue Oct 1
05:24:09 UTC
2019 x86_64 x86_64 x86_64 GNU/Linux
输入命令后可以看到内核版本4.15.0-66,系统x86_64
- 卸载旧版本,如果以前安装过的话
$ sudo apt-get remove docker docker-engine docker.io containerd runc
- 使用官网提供的仓库安装
首次在新主机上安装社区版之前,需要设置Docker存储库。之后,您可以从存储库安装和更新Docker。- 设置仓库源
# 1. 更新apt索引
$ sudo apt-get update
# 2. Install packages to allow apt to use a repository over HTTPS:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# 3. 添加Docker的官方GPG密钥,
# 添加完秘钥后会显示OK,然后验证是否一致 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88
# 使用以下命令设置稳定仓库。
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
正式开始安装Docker社区版
INSTALL DOCKER ENGINE - COMMUNITY
- 更新apt索引
sudo apt-get update
- 直接安装最新版本,或者直接到下一步安装指定版本
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- 安装docker指定版本
a. 列出你的仓库的所有的版本
$ apt-cache madison docker-ce
docker-ce | 5:19.03.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
docker-ce | 5:19.03.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
...
b. 通过指定<VERSION_STRING>安装制定版本,比如5:19.03.83-0ubuntu-bionic
$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
以上所有命令合集
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
docker -v
安装成功
- 运行hello world映像,验证Docker Engine-Community是否正确安装
$ sudo docker run hello-world
此命令下载测试映像并在容器中运行它。当容器运行时,它会打印一条信息性消息并退出。效果如下:
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:f9dfddf63636d84ef479d645ab5885156ae030f611a56f3a7ac7f2fdd86d7e4e
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/
root@instance$
参考文献:
docker官网 Get Docker Engine - Community for Ubuntu 2020/03/18