10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Raspberry Pi に upstart と Docker をインストール

Posted at

概要

Raspberry Pi に Docker をインストールする場合,ARM 用のパッケージを使う.この時,サービス管理に upstart を使っていると,upstart 用の設定ファイルが見つからずインストールが失敗する.そのため,他の環境から設定ファイルをコピーしておく必要がある.

Hypriot Docker

ARM 用の Docker パッケージとして,Hypriot Docker Debian Packages を使う.ダウンロードは ここ からできて,インストール方法も書いてある.

ただし,upstart を使っている場合,設定ファイルが足りずインストールが失敗するため,下記の docker.conf を /etc/init/ に用意しておく.

docker.conf
description "Docker daemon"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]
limit nofile 524288 1048576
limit nproc 524288 1048576

respawn
kill timeout 20

pre-start script
    if grep -v '^#' /etc/fstab | grep -q cgroup \
        || [ ! -e /proc/cgroups ] \
        || [ ! -d /sys/fs/cgroup ]; then
        exit 0
    fi
    if ! mountpoint -q /sys/fs/cgroup; then
        mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
    fi
    (
        cd /sys/fs/cgroup
        for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
            mkdir -p $sys
            if ! mountpoint -q $sys; then
                if ! mount -n -t cgroup -o $sys cgroup $sys; then
                    rmdir $sys || true
                fi
            fi
        done
    )
end script

script
    DOCKER=/usr/bin/$UPSTART_JOB
    DOCKER_OPTS=
    if [ -f /etc/default/$UPSTART_JOB ]; then
        . /etc/default/$UPSTART_JOB
    fi
    exec "$DOCKER" daemon $DOCKER_OPTS
end script

post-start script
    DOCKER_OPTS=
    if [ -f /etc/default/$UPSTART_JOB ]; then
        . /etc/default/$UPSTART_JOB
    fi
    if ! printf "%s" "$DOCKER_OPTS" | grep -qE -e '-H|--host'; then
        while ! [ -e /var/run/docker.sock ]; do
            initctl status $UPSTART_JOB | grep -qE "(stop|respawn)/" && exit 1
            echo "Waiting for /var/run/docker.sock"
            sleep 0.1
        done
        echo "/var/run/docker.sock is up"
    fi
end script

その後,パッケージファイルをダウンロードしインストールする.

$ wget http://downloads.hypriot.com/docker-hypriot_1.8.3-1_armhf.deb
$ sudo dpkg -i docker-hypriot_1.8.3-1_armhf.deb

参考

そもそも Raspbian ではなく,Docker インストール済みの OS (HypriotOS) を使うこともできる.その場合は,Raspberry Piでdockerを使う(HypriotOS) が参考になる.

10
10
4

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
10
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?