Docker公式通りにRaspi3にDockerをインストールする
概要
Raspi3B+にDockerをインストールしてみました。公式では64ビット版しかサポートされていないと記述がありますが、32ビット版のRaspbianでもインストールできました。
参考にしたURL
対応するOS
Docker CE(Community Edition)をインストールするためには、以下のDebianまたはRaspbianのバージョンのうち64ビットバージョンが必要です。
- Buster 10 (Docker CE 17.11 Edge only)
- Stretch 9 (stable) / Raspbian Stretch
- Jessie 8 (LTS) / Raspbian Jessie
- Wheezy 7.7 (LTS)
Docker CEはJessieおよびStretchのため、x86_64(またはamd64)およびarmhf双方のアーキテクチャをサポートしています。
あれ待てよ
Raspbianって32ビットOSじゃなかったっけ?巷ではラズパイにDockerインストールした的なブログが沢山あるけど、それって64ビット版でやってるのかな?そうとは思えないので、とりあえず無視してインストールを試みてみる。
OS確認
次のコマンドでインストール対象のOSを確認します。 今回は32ビットのRaspbian stretchでした(armv7は32ビットです)。
pi@raspberrypi:~ $ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 9.6 (stretch) Release: 9.6 Codename: stretch pi@raspberrypi:~ $ uname -m armv7l
インストールの方法について
現在Dockerのインストール方法には3種類存在します。しかしながら、Raspbianにインストールする場合は、そのうち1種類の方法でしかできないようです(公式ではconvenience scriptsによるインストールと記載されています)。この便利なスクリプトによるインストールは、試験や開発用途でDockerを利用する場合のインストール方法で、製品での使用は非推奨のインストール方法です。
便利なスクリプトを利用したインストール
スクリプトは、Docker Install Repositoryで提供されています。Edge用とTest用の2つのスクリプトが提供されています。このうちどちらかをインストールすれば良いです。今回はEdge用をインストールしてみました。
pi@raspberrypi:~ $ curl -fsSL https://get.docker.com -o get-docker.sh pi@raspberrypi:~ $ sudo chmod +x ./get-docker.sh pi@raspberrypi:~ $ sudo sh get-docker.sh
# Executing docker install script, commit: 46dc063 + sh -c apt-get update -qq >/dev/null + sh -c apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null + sh -c curl -fsSL "https://download.docker.com/linux/raspbian/gpg" | apt-key add -qq - >/dev/null Warning: apt-key output should not be parsed (stdout is not a terminal) + sh -c echo "deb [arch=armhf] https://download.docker.com/linux/raspbian stretch edge" > /etc/apt/sources.list.d/docker.list + [ raspbian = debian ] + sh -c apt-get update -qq >/dev/null + sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null + sh -c docker version Client: Version: 18.09.0 API version: 1.39 Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:57:21 2018 OS/Arch: linux/arm Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.0 API version: 1.39 (minimum version 1.12) Go version: go1.10.4 Git commit: 4d60db4 Built: Wed Nov 7 00:17:57 2018 OS/Arch: linux/arm Experimental: false If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like: sudo usermod -aG docker your-user Remember that you will have to log out and back in for this to take effect! WARNING: Adding a user to the "docker" group will grant the ability to run containers which can be used to obtain root privileges on the docker host. Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface for more information.
非rootユーザでもDockerを使用したい場合には、dockerグループにユーザを追加する旨の表示が出て、特に問題なくインストールできた感じ(インストール時間はラズパイ3B+で数分程度)。
動作確認
pi@raspberrypi:~ $ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 61e750ce94d2: Pull complete Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 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. (arm32v7) 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/ pi@raspberrypi:~ $ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f39b648d9cd1 hello-world "/hello" 21 seconds ago Exited (0) 19 seconds ago agitated_pare pi@raspberrypi:~ $
とりあえずインストールできたみたいです。
Dockerの更新について
スクリプトによりインストールされたDockerの更新は、パッケージ管理を利用してください。スクリプトを再実行した場合、問題が発生します(リポジトリの再追加)。