LoginSignup
16
22

More than 5 years have passed since last update.

Raspberry Pi 3で、Wi-Fi アクセスポイントルータ (Docker版)

Last updated at Posted at 2017-12-07
  • 玄関開けたら2分でWifi-AP.

  • (2017-12-7 10am GMT+9) 限定公開のままだったので、手動で変更

概要

TL;DR

  • Dockerが動いている方は、↓でお試し。

    docker run -d --rm --net=host --privileged mt08/rpi-ap
    
    # デフォルト設定
    # SSID: `Pi3-AP`
    # Passphrase: `raspberry`
    
  • makeを使って、

    こんな感じで
    sudo apt install -y git make && git clone https://github.com/mt08xx/docker-rpi-ap.git && cd docker-rpi-ap/
    # 実行
    # SSID、PASSWORD(8~63文字) Channel番号は、変更可能
    make run SSID=foobar PASS=hogehoge CH=3
    
  • WifiはAPとして使われるので、SSHを使ってる場合、有線LANを使用すること。

環境

  • Raspberry Pi 3 model B
    • microSD 16GB (読み書き速いのがいいよ)
    • Raspbian: 2017-11-29-raspbian-stretch-lite 使用
    • 有線LANをインターネットに接続
    • Wifiは、APとして使われる。(デフォルトでIP:192.168.42.1となる)
  • microSDイメージ焼きと端末
    • Windows 10 64bit
    • Etcherにて、イメージをSDに焼いた。
    • 端末ソフト: Teraterm

手順

Raspbian導入

  • いつものツールで、いつも通りに焼き上げる。
  • sshできるようにして、ラズパイにログインする.

Docker 導入

Docker導入
# Docker導入
curl -sSL https://get.docker.com/ | sh
# ユーザをdockerグループに所属(反映するのに、再起動)
sudo usermod -aG docker ${USER}
# Docker動作確認
sudo docker run --rm hello-world

# エラーでたらダウングレード、Versionロックして、動作確認 >>  docker: Error response from daemon: ~~~~
# 使えるパッケージのバージョンは、apt-cache policy docker-ceで確認できる
sudo apt install -y --allow-downgrades docker-ce=17.10.0~ce-0~raspbian
sudo apt-mark hold docker-ce
sudo docker run --rm hello-world

# うまく動いたら、再起動
sudo reboot
hello-world実行例(このメッセージが出ればOK)
pi@raspberrypi:~ $ sudo docker run --rm hello-world

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.
    (arm32v5)
 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://cloud.docker.com/

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

pi@raspberrypi:~ $

アクセスポイント導入・実行

# makeでいろいろできるようにしたので、こちらで。
# 
sudo apt install -y git make
git clone https://github.com/mt08xx/docker-rpi-ap.git
cd docker-rpi-ap/

# 実行
# SSID、PASSWORD(8~63文字) Channel番号は、変更可能
make run SSID=foobar PASS=hogehoge CH=3

# 止める場合
# make stop

# なんかおかしい場合、ターミナル入出力で起動(CTRL-p CTRL-q でコンテナを止めずに抜けれる)
# make run DAEMON=0

ファイル構成と仕組み

  • docker起動時のオプション --net=host --privileged使って、ホストのネット環境をコンテナから使用。
  • ソースは、https://github.com/mt08xx/docker-rpi-ap.git

    • Makefile: make ほげほげ 、でいろいろやってくれる。

      • 運用向け
        • make run: 開始(オプション:SSID, PASS, CH, DAEMON)
        • make stop: コンテナ停止
        • make status: docker ps -a
      • 開発向け
        • make build: Docker イメージビルド
        • make clean: コンテナ停止・削除、イメージ削除
    • Dockerfile: イメージ作成に使用

    • rpi-ap_start.sh: 起動時にコンテナ内で呼ばれるスクリプト

      • 環境変数から、設定を読み取って、dhcpd.confhostapd.confの生成 ip_forward設定をする。
      • Makefileには書いてないけど、いろいろ設定できるはず..

その他

  • wifiをインターネット側、有線にクライアントを接続もできる(ハズ...)

    • 遠くにある有線機器をネットにつなぎたい?
    • -e AP_ENABLE_HOSTAPD=0で、hostapdを起動しない。
    rpi-ap_start.sh内で
    ...
    : ${AP_INTERFACE_OUTGOING:=eth0}
    ...
    : ${AP_INTERFACE:=wlan0}
    

    としてるので、docker run のパラメータに-e AP_ENABLE_HOSTAPD=0 -e AP_INTERFACE_OUTGOING=wlan0 -e AP_INTERFACE=eth0と設定する.

16
22
0

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
16
22