Ubuntu 16.04下docker ce的安裝

卸載版本的docker

sudo apt-get remove docker docker-engine docker.io

安裝可選內核模塊

從 Ubuntu 14.04 開始,一部份內核模塊移到了可選內核模塊包 ( linux-image-extra-* ) ,以
減小內核軟件包的體積。正常安裝的系統應該會包含可選內核模塊包,而一些裁剪後的系統
可能會將其精簡掉。 AUFS 內核驅動屬於可選內核模塊的一部分,做爲推薦的 Docker 存儲層
驅動,通常建議安裝可選內核模塊包以使用 AUFS 。若是沒有安裝的話能夠使用下面的命令安裝linux

sudo apt-get update
sudo apt-get install  linux-image-extra-$(uname -r)  linux-image-extra-virtual

安裝Docker CE

因爲 apt 源使用 HTTPS 以確保軟件下載過程當中不被篡改。所以,咱們首先須要添加使用
HTTPS 傳輸的軟件包以及 CA 證書。docker

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

鑑於國內網絡問題,強烈建議使用國內源,官方源請在註釋中查看。爲了確認所下載軟件包的合法性,須要添加軟件源的 GPG 密鑰json

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 軟件源ubuntu

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/

若是出現上述信息,說明安裝成功bash

鏡像加速

因爲國外的鏡像有時候網絡訪問過慢,須要使用國內的鏡像加速網絡

對於使用 systemd 的系統,請在 /etc/docker/daemon.json 中寫入以下內容(若是文件不存
在請新建該文件)app

{
"registry-mirrors": [
    "https://registry.docker-cn.com"
    ]
}

以後重啓啓動系統curl

sudo systemctl daemon-reload
sudo systemctl restart docker
相關文章
相關標籤/搜索