卸載版本的docker
sudo apt-get remove docker docker-engine docker.io
安裝可選內核模塊
從 Ubuntu 14.04 開始,一部分內核模塊移到了可選內核模塊包 ( linux-image-extra-* ) ,以
減少內核軟件包的體積。正常安裝的系統應該會包含可選內核模塊包,而一些裁剪后的系統
可能會將其精簡掉。 AUFS 內核驅動屬於可選內核模塊的一部分,作為推薦的 Docker 存儲層
驅動,一般建議安裝可選內核模塊包以使用 AUFS 。如果沒有安裝的話可以使用下面的命令安裝
sudo apt-get update
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
安裝Docker CE
由於 apt 源使用 HTTPS 以確保軟件下載過程中不被篡改。因此,我們首先需要添加使用
HTTPS 傳輸的軟件包以及 CA 證書。
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
鑒於國內網絡問題,強烈建議使用國內源,官方源請在注釋中查看。為了確認所下載軟件包的合法性,需要添加軟件源的 GPG 密鑰
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# 官方源
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
然后,我們需要向 source.list 中添加 Docker 軟件源
sudo add-apt-repository \
"deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) \
stable"
# 官方源
# sudo add-apt-repository \
# "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
# $(lsb_release -cs) \
# stable
更新 apt 軟件包緩存,並安裝 docker-ce
sudo apt-get update
sudo apt-get install docker-ce
啟動docker CE
sudo systemctl enable docker
sudo systemctl start docker
測試安裝是否正確
sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:445b2fe9afea8b4aa0b2f27fe49dd6ad130dfe7a8fd0832be5de99625dad47cd
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
如果出現上述信息,說明安裝成功
鏡像加速
由於國外的鏡像有時候網絡訪問過慢,需要使用國內的鏡像加速
對於使用 systemd 的系統,請在 /etc/docker/daemon.json 中寫入如下內容(如果文件不存
在請新建該文件)
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}
之后重啟啟動系統
sudo systemctl daemon-reload
sudo systemctl restart docker