RaspiにDockerを入れる

作業

公式サイト

Redirecting…

に書いているとおりにしてインストール

Raspbian users cannot use this method!

For Raspbian, installing using the repository is not yet supported. You must instead use the convenience script.

と書いているのでスクリプトを使う。 Raspiにログインして、root userにしてから

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

しかし、エラーが出る.いろんな解決法が出ているが、結局rebootするのでうまく行った。

# Executing docker install script, commit: f45d7c11389849ff46a6b4d94e0dd1ffebca32c1
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive 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 stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
E: Sub-process /usr/bin/dpkg returned an error code (1)
root@da-vinci:/home/endo# apt-get autoremove
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 4 個。
1 個のパッケージが完全にインストールまたは削除されていません。
この操作後に追加で 0 B のディスク容量が消費されます。
docker-ce (5:19.03.5~3-0~raspbian-stretch) を設定しています ...
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
invoke-rc.d: initscript docker, action "start" failed.
 127 00:47:22 da-vinci systemd[1]: docker.service: Unit entered failed state.
 127 00:47:22 da-vinci systemd[1]: docker.service: Failed with result 'exit-code'.
dpkg: パッケージ docker-ce の処理中にエラーが発生しました (--configure):
 サブプロセス インストール済みの post-installation スクリプト はエラー終了ステータス 1 を返しました
処理中にエラーが発生しました:

rebootしてから

# apt-get install -y -q docker-engine
# curl -fsSL https://get.docker.com -o get-docker.sh
# sh get-docker.sh

するとうまく入るようだ.

# Executing docker install script, commit: f45d7c11389849ff46a6b4d94e0dd1ffebca32c1
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
W: APT had planned for dpkg to do more than it reported back (0 vs 4).
   Affected packages: docker-ce:armhf
+ 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 stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:36:04 2019
 OS/Arch:           linux/arm
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:30:06 2019
  OS/Arch:          linux/arm
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
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.

docker-compose

$ git clone https://github.com/docker/compose.git
$ ./script/build/linux
$ cd dist
$ ./docker-compose-*** version

バイナリをbin以下にコピーする。

$ sudo cp docker-compose-Linux-armv7l /usr/local/bin/docker-compose
$ sudo chown root:root /usr/local/bin/docker-compose
$ sudo chmod 755 /usr/local/bin/docker-compose

参考ページ

Raspbian上にdockerインストールでエラーにもめげずCentOS動かした件 - Qiita

Docker comes to Raspberry Pi - Raspberry Pi

Redirecting…

起動

$ systemctl start docker
or
# 自動起動
$ systemctl enable docker

check

$ systemctl status docker

info

$ docker info

Docker command

download start

$ docker run --name some-nginx -d -p 8080:80 nginx

image

$ docker images

ps

$ docker ps

stop

$ docker stop some-nginx

delete

delete container

$ docker rm some-nginx

delete image

$ docker rmi nginx

Docker compose

コンテナ開始

$ docker-compose up

バックグラウンドで実行

$ docker-compose up -d