1. 程式人生 > >Ubuntu 16.04下docker ce的安裝

Ubuntu 16.04下docker ce的安裝

參見:https://www.cnblogs.com/senlinyang/p/8203191.html

解除安裝版本的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