HippoBlog
Web開発に関する備忘録や
日々の雑記ブログ
  • #RaspberryPi
  • 2019年7月13日
ENTRY TITLE

[raspi] ラズパイにDockerをインストールする(蛇足あり)

TEXT BY @hippohack@hippohack
TEXT BY @hippohack@hippohack
  • このエントリーをはてなブックマークに追加

ちゃんとラズビアン対応してるのがおもしろい。

旧バージョンの削除

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

あるなら、/var/lib/docker/ にもろもろあるはず。

Docker CEのインストール

基本的には、Dockerのリポジトリを設定してからインストールする必要があるみたいやが、ラズビアンについては除外されるみたい。

用意されたスクリプトでインストールする

$ curl -fsSL https://get.docker.com -o get-docker.sh

$ sudo sh get-docker.sh 
# Executing docker install script, commit: 4957679
+ sh -c apt-get update -qq >/dev/null
W: http://deb.goaccess.io/dists/jessie/InRelease の取得に失敗しました  期待されるエントリ 'main/binary-armhf/Packages' が Release ファイル内に見つかりません (誤った sources.list エントリか、壊れたファイル)

E: いくつかのインデックスファイルのダウンロードに失敗しました。これらは無視されるか、古いものが代わりに使われます。

なんか全然あかんかったけど???

で、結局イチからやることに。ということで「インストール」に戻る。

Docker repositoryのセットアップ

$ sudo apt-get update

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

official GPG key の追加(?)

$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

フィンガープリントの確認

$ sudo apt-key fingerprint 0EBFCD88

リポジトリの指定 [ armhf ] のタブ ← ここ注意。ずっと違うやつでやっててはまった。

$ echo "deb [arch=armhf] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
     $(lsb_release -cs) stable" | \
    sudo tee /etc/apt/sources.list.d/docker.list

$ sudo apt update
$ sudo apt install docker-ce
$ which docker
/usr/bin/docker

入った。

バージョン指定するなら

$ apt-cache madison docker-ce
 docker-ce | 18.06.1~ce~3-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 18.06.0~ce~3-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 18.03.1~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 18.03.0~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 17.12.1~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 17.12.0~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 17.09.1~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages
 docker-ce | 17.09.0~ce-0~raspbian | https://download.docker.com/linux/raspbian/ jessie/stable armhf Packages

$ sudo apt-get install docker-ce=<VERSION_STRING>

起動確認

$ sudo docker run armhf/hello-world
Unable to find image 'armhf/hello-world:latest' locally
latest: Pulling from armhf/hello-world
a0691bf12e4e: Pull complete 
Digest: sha256:9701edc932223a66e49dd6c894a11db8c2cf4eccd1414f1ec105a623bf16b426
Status: Downloaded newer image for armhf/hello-world:latest

Hello from Docker on armhf!
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.
 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 Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

アップデートするとき

$ sudo apt-get update

起動時に有効化

$ sudo systemctl enable docker
$ sudo systemctl start docker

Install Docker Compose for Raspbian

pip を使うんだって。

$ sudo pip install docker-compose
︙
Compiling /tmp/pip-build-zy5iHD/docker/docker/api/mixin.py ...
  File "/tmp/pip-build-zy5iHD/docker/docker/api/mixin.py", line 8
    base_url: str = ''
            ^
SyntaxError: invalid syntax
︙

なんかやばそうだが、はいったみたい。

$ which docker-compose
/usr/local/bin/docker-compose

インストール後の手順

sudoつけないとdocker runできないのでユーザーの設定はしたほうがいいかも。

$ sudo groupadd docker 
$ sudo usermod -aG docker $USER

要リスタート。

参考


最後までお読みいただき、ありがとうございました。

ご意見などありましたら@hippohackへDMをお願いいたします。

  • このエントリーをはてなブックマークに追加