安裝前準備有助於加快安裝速度
更換源,本教程內選擇更換到阿里的源:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
安裝方式
- 基於Ubuntu安裝docker的方式有兩種,本教程內主要介紹使用 Docker 倉庫進行安裝的方式。
設置倉庫
- 在新主機上首次安裝 Docker Engine-Community 之前,需要設置 Docker 倉庫。之後就可以從倉庫安裝和更新 Docker 。
更新 apt 包索引。
sudo apt-get update
安裝 apt 依賴包,用於通過HTTPS來獲取倉庫:
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
添加 Docker 的官方 GPG 密鑰:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 通過搜索指紋的後8個字符,驗證是否擁有帶有指紋的密鑰:
sudo apt-key fingerprint 0EBFCD88
設置穩定版倉庫
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
安裝 Docker Engine-Community
在次更新 apt 包索引。
sudo apt-get update
安裝最新版本的 Docker Engine-Community 和 containerd :
sudo apt-get install docker-ce docker-ce-cli containerd.io
或者安裝特定版本,先列出倉庫中可用的docker-ce和docker-ce-cli版本:
apt-cache madison docker-ce
apt-cache madison docker-ce-cli
選擇指定版本進行安裝即可,舉例如下
sudo apt-get install docker-ce=<5:19.03.8~3-0~ubuntu-xenial> docker-ce-cli=<5:19.03.8~3-0~ubuntu-xenial> containerd.io
安裝完成後,查看docker版本:
sudo docker version
或者運行如下命令測試docker是否安裝成功
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/
如果需要再docker容器內聯網安裝工具,比如vim,可以這樣做:
進入容器-》更新到阿里源-》sudo apt-get update ,之後就可以正常使用 apt-get install 進行安裝了
安裝ping、ifconfig命令
apt-get install iputils-ping
apt-get install net-tools