LoginSignup
3
5

More than 3 years have passed since last update.

ラズパイにDockerインストールするメモ

Last updated at Posted at 2020-07-19

はじめに

勉強のため、Docker環境ほしくてラズパイにDockerをインストールする方法を調べたので、わすれないようにメモ

※ docker-compose はインストールできず、失敗理由はおまけに書いといた
 →※おまけ※ Docker-composeはインストールできず

2020/7/20 追記 docker-compose インストール方法を @mt08 さんに教えて頂きました!コメント欄をご覧ください。(ありがとうございます!)

参考

インストール方法は、ここ→Install Docker Engine on Ubuntu にありました。

↓ 参考サイトから抜粋

Install using the convenience script
Docker provides convenience scripts at get.docker.com and test.docker.com for installing edge and testing versions of Docker Engine - Community into development environments quickly and non-interactively. The source code for the scripts is in the docker-install repository. Using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:

脊髄反射でgoogle翻訳

便利なスクリプトを使用してインストールする
Dockerのget.docker.comとtest.docker.comには、Docker Engineのエッジバージョンとテストバージョンをインストールするための便利なスクリプトが用意されており、コミュニティを迅速かつ非対話的に開発環境に組み込むことができます。スクリプトのソースコードは、docker-installリポジトリにあります。これらのスクリプトを使用することは本番環境では推奨されません。使用する前に、潜在的なリスクを理解する必要があります。

"本番利用はやめたほうがいいよ", "自己責任で使ってね" と言うことっぽい。

Dockerインストール

インストールは簡単。取得したシェルスクリプトを実行するだけ。(シェル作ってくれた方、ありがとうございます)

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

piユーザーがDockerを使えるようdockerグループに追加

$ sudo usermod -aG docker pi

これでおわり。グループ追加後にpiユーザーでサインインすればDocker使える。

Dockerのバージョンを確認

$ docker version
Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a6621
 Built:             Mon Jun 22 15:53:41 2020
 OS/Arch:           linux/arm
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.12
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.13.10
  Git commit:       48a6621
  Built:            Mon Jun 22 15:47:34 2020
  OS/Arch:          linux/arm
  Experimental:     false
 containerd:
  Version:          1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

ラズパイの情報

Dockerインストールに使ったラズパイ Raspberry Pi 4 model B (メモリ4GB) の情報です。OSは、32bit, 64bit の2種類で試しました。(リンク:64bit OSのインストール)

32bit OS

$ cat /etc/debian_version
10.4
$ cat /etc/issue
Raspbian GNU/Linux 10 \n \l
$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
$ uname -s
Linux
$ uname -m
armv7l

64bit OS

$ cat /etc/debian_version
10.4
$ cat /etc/issue
Debian GNU/Linux 10 \n \l
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
$ uname -s
Linux
$ uname -m
aarch64

動作確認

Dockerコンテナを起動して、NginxでWebサーバーをたててみる。

$ docker run --name some-nginx -d -p 8080:80 nginx
$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              43362c1f9f7a        8 days ago          102MB
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
060c8f076916        nginx               "/docker-entrypoint.…"   13 minutes ago      Up 13 minutes       0.0.0.0:8080->80/tcp   some-nginx

ブラウザでWebサイトが開けば成功

image.png

line.png

※おまけ※ Dockerインストール失敗例

  • 私が使用したラズパイOSでは、公式リポジトリにパッケージが無いらしい。
  • 公式リポジトリにパッケージが無いと、sudo apt-get install docker-ce でDockerインストールできない
  • sudo apt-get install docker-ce でDockerインストールするために、外部リポジトリを登録する
  • 外部リポジトリの登録は、add-apt-repositoryコマンドを使う
    • 豆: 外部リポジトリは、PPA(Personal Package Archives)と呼称されることもある
  • 外部リポジトリを登録するため以下コマンドを実行したけど、エラー発生し登録できなかった。
 $ sudo add-apt-repository "deb [Arch=AMD64] https://download.docker.com/linux/ubuntu bionic test"
Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 95, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 109, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 599, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)
  File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 93, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/buster

※おまけ※ Docker-composeはインストールできず →追記:できた!

ーーーー
2020/7/20 追記 docker-compose インストール方法を @mt08 さんに教えて頂きました!コメント欄をご覧ください。(ありがとうございます!)

# 教えて頂いたインストールのコマンド
$ sudo apt-get install -y libffi-dev libssl-dev
$ sudo apt-get install -y python3 python3-pip
$ sudo pip3 install docker-compose

ーーーー

Docker-composeのインストールも挑戦したのですが失敗しました。どうやら、ラズパイに適したモジュールが無いようです。以下、私が調べたことのメモです。

Docker-composeのインストール方法は、Install Docker Composeに書いてて、以下を実行すればいけるらしい。でも、失敗しました。

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

1つ目のコマンドにあるURL https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m) に合致するモジュールが無いようです。

unameの実行結果はこちら

# OS名を表示
$ uname -s
Linux

# マシン(ハードウェア)のタイプを表示
$ uname -m
armv7l

つまり、docker-compose-$(uname -s)-$(uname -m) とは、docker-compose-Linux-armv71となります。

そして、https://github.com/docker/compose/releases には、docker-compose-Linux-armv71というモジュールがありません。

image.png

ためしに、docker-compose-Linux-x86_64 を使ってみたのですが、エラーで動かなかった(まぁ、そーですよね)

$ docker-compose -v
-bash: /usr/local/bin/docker-compose: バイナリファイルを実行できません: 実行形式エラー
3
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5