前言
參考Docker官方文檔在阿里云ECS實例上安裝Docker际度。
官方文檔:https://docs.docker.com/install/linux/docker-ce/ubuntu/
安裝要求
Docker CE要求的Ubuntu版本:
- Disco 19.04
- Cosmic 18.10
- Bionic 18.04 (LTS)
- Xenial 16.04 (LTS)
# 查看系統(tǒng)版本
$ cat /proc/version
Linux version 4.4.0-142-generic (buildd@lgw01-amd64-033) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019
# 查看發(fā)行版名稱
$ lsb_release -cs
xenial
卸載舊版本(略)
$ sudo apt-get remove docker docker-engine docker.io containerd runc
準(zhǔn)備工作
# 更新源
$ sudo apt-get update
# 安裝必要的工具,如HTTPS工具钝吮、GPG工具等
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# 添加docker的gpg秘鑰到apt-key密鑰中,用于確認所下載的軟件包的合法性
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 添加docker源
# 可以使用aliyun的內(nèi)網(wǎng)鏡像代替:http://mirrors.cloud.aliyuncs.com/docker-ce/linux/ubuntu
$ 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 version
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
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/
至此docker已正確安裝