警告:切勿在沒有配置 Docker APT 源的狀況下直接使用 apt 命令安裝 Docker.linux
Docker CE 不只支持 x86_64
架構的計算機,同時也支持 ARM
架構的計算機,本小節內容以樹莓派單片電腦爲例講解 ARM
架構安裝 Docker CE。docker
Docker CE 支持如下版本的 Raspbian 操做系統:ubuntu
Raspbian Stretch緩存
Raspbian Jessie安全
注: Raspbian
是樹莓派的開發與維護機構 樹莓派基金會 推薦用於樹莓派的首選系統,其基於 Debian
。bash
因爲 apt 源使用 HTTPS 以確保軟件下載過程當中不被篡改。所以,咱們首先須要添加使用 HTTPS 傳輸的軟件包以及 CA 證書。網絡
$ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg2 \ lsb-release \ software-properties-common
鑑於國內網絡問題,強烈建議使用國內源,官方源請在註釋中查看。架構
爲了確認所下載軟件包的合法性,須要添加軟件源的 GPG 密鑰。app
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add -
# 官方源 # $ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
而後,咱們須要向 source.list
中添加 Docker CE 軟件源:dom
$ sudo add-apt-repository \
"deb [arch=armhf] https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian \ $(lsb_release -cs) \ stable" # 官方源 # $ sudo add-apt-repository \ # "deb [arch=armhf] https://download.docker.com/linux/raspbian \ # $(lsb_release -cs) \ # stable"
以上命令會添加穩定版本的 Docker CE APT 源,若是須要測試或每日構建版本的 Docker CE 請將 stable 改成 test 或者 nightly。
更新 apt 軟件包緩存,並安裝 docker-ce
。
$ sudo apt-get update $ sudo apt-get install docker-ce
在測試或開發環境中 Docker 官方爲了簡化安裝流程,提供了一套便捷的安裝腳本,Raspbian 系統上可使用這套腳本安裝:
$ curl -fsSL get.docker.com -o get-docker.sh $ sudo sh get-docker.sh --mirror Aliyun
執行這個命令後,腳本就會自動的將一切準備工做作好,而且把 Docker CE 的 Edge 版本安裝在系統中。
$ sudo systemctl enable docker $ sudo systemctl start docker
默認狀況下,docker
命令會使用 Unix socket 與 Docker 引擎通信。而只有 root
用戶和 docker
組的用戶才能夠訪問 Docker 引擎的 Unix socket。出於安全考慮,通常 Linux 系統上不會直接使用 root
用戶。所以,更好地作法是將須要使用 docker
的用戶加入 docker
用戶組。
創建 docker
組:
$ sudo groupadd docker
將當前用戶加入 docker
組:
$ sudo usermod -aG docker $USER
退出當前終端並從新登陸,進行以下測試。
$ docker run arm32v7/hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c 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/
若能正常輸出以上信息,則說明安裝成功。
注意: ARM 平臺不能使用 x86
鏡像,查看 Raspbian 可以使用鏡像請訪問 arm32v7。
鑑於國內網絡問題,後續拉取 Docker 鏡像十分緩慢,強烈建議安裝 Docker 以後配置鏡像加速