A Dreamer's Lair

Setting up a fresh Raspberry PI 3 with Docker

I already mentioned in a previous post that I am moving away from several of my existing systems to replace them with new, and hopefully more reliable, solutions.

Not too long ago I started out experimenting with Docker containers on my Synology NAS and I must say that this has turned out quite well. Because of this I am planning to use Docker for all my new domotica where possible.

I intend to use a Raspberry PI 3 as a docker host. In the future I could even include Docker Swarm to make my domotica available 24/7 even when some hardware fails.

Setting up a PI 3 for Docker is already described in several posts on the great wide internet. Below I will describe the method I used including the links for that. No need to reinvent the wheel now is there!

Prepare SD/USB

The first step in setting up the PI is to prepare both a micro SD card and a USB thumb drive. I want to use the USB drive as my main memory device on the PI because it is less vulnerable then a micro SD card. But to be able to use a USB drive one first has to start with a micro SD card.

So from the Raspberry site itself I downloaded the lastest Raspbian Stretch Lite. The Lite version of course since I don’t want to use the GUI.

So download the image from here.

For writing the downloaded image to the SD card and USB drive Raspberry suggests Etcher which works just fine. See here.

I follow the instructions and now have both a micro SD card and a USB drive with Raspbian Stretch Lite on them.

On both the images I added an empty file called ssh so ssh is enabled by default when booting.

Boot and program USB mode

Next step is to connect the PI to the desired peripherals of choice (display, ethernet, keyboard, mouse etc).

Then insert the micro SD card and turn the power on (insert micro USB power cable).

We now want to program the USB mode on the PI. How to do this can be found here. So program the USB mode, reboot the PI and check if USB mode has been enabled.

When you have confirmed that USB mode is active, we can power off the Raspberry with the following command

sudo poweroff

Boot from USB, initial setup

Next step is to boot from the USB drive. So remove the micro SD card from the PI and attach the prepared USB drive. Again power on the PI and wait for it to have booted.

The first thing after we have logged in, is to change the password for the user pi. You can do this with the command passwd. Make sure it’s a strong password!

Next we want to make sure the PI has all the latest updates:

sudo apt-get update
sudo apt-get upgrade

Next we start the configuration tool using the command sudo raspi-config. With this configuration we need to change the folllowing stuff:

  • Hostname -> choose an appropiate one (for example DOM-PI01 for domotica PI number 1)
  • Wi-fi -> Enter your SSID and passphrase to enable Wi-fi. I want this enabled so I don’t need to have the PI connected with an UTP-cable.
  • Localisation options -> Change the timezone, keyboard layout and Wi-fi country to what’s applicable.
  • Advanced options -> Choose the smallest possible memory split of 16MB to free up as much RAM as possible. This because we don’t use a GUI anyway.

Quit the tool and let the PI reboot.

Next step is to make the IP-address for the WLAN static (make sure you reserve it on your router!) so the PI can be accessed wirelessly through a fixed IP-address.

Enter the following command to open the dhcp config

sudo nano /etc/dhcpcd.conf

Add the following lines to the config

interface wlan0
static ip_address=<your-static-ip>/24
static routers=<ip-to-your-gateway>
static domain_name_servers=<ip-to-your-dns-server>

(if you want you can do this for the LAN too. Simply use ‘interface eth0’)

Press Ctrl-X then Y to save the file and exit nano.

We now reboot one more time and again log in to the PI. Now verify with ifconfig that the WLAN0 is using the correct assigned IP-address.

Since I am now done with the initial setup, I power off my PI (sudo poweroff) and then remove the power cable.
Now I can remove the keyboard, mouse and monitor since they are no longer necessary.

When you have done this power up the PI by connecting the micro USB cable and let it boot. To access it you can use any SSH client. I use the free tool Bitvise SSH Client.

Setup watch dog and monitor tools

To monitor the PI so it for example automatically reboots when it hangs you can use watchdos and monitor tools. The DomoticZ site shows some nice options for this.

I installed the watchdog and Monit.

Add the Aeon Labs Z-Stick

Since I am planning to use the Aeon Labs Z-Stick (gen2 in my case) I insert the device into the PI. Since there are several reports of issues with such hardware after rebooting, I create a symbolic link again with useful help of Domoticz.

I opened the configuration with

sudo nano /etc/udev/rules.d/99-usb-serial.rules

and since I use a gen-2 Z-Stick I added the following line to it

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="ttyUSB-ZStick-GEN2"

I can now access my Z-Stick hardware using the device

/dev/ttyUSB-ZStick-GEN2

regardless of the physical USB port it is attached to.

Mount a folder from my Synology NAS

To be able to more conveniently see data files which the docker containers use, I have created a shared folder on my NAS called dockerdata. To use this on the PI I have to mount an NFS volume on it.

First create the folder locally on the PI

mkdir /home/pi/dockerdata

The open fstab

sudo nano /etc/fstab

and add the following line to it

<ip-of-your-nas>:/volume1/dockerdata /home/pi/dockerdata nfs defaults 0 0

This assumes that you have a shared folder called dockerdata on your NAS.

Mount the volume

sudo mount -a

and check if the folder /home/pi/dockerdata reflects the contents of /volume1/dockerdata.

Install Docker CE

The final step in setting up our PI for docker is to install Docker itself.

You can do this simply by entering

curl -sSL https://get.docker.com | sh

Docker CE will now be installed.

And there you have it. The PI is ready to be used as a Docker Host!

    Or

    Your email address will not be published. Required fields are marked *

    *



    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>