Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
getting-started:raspberry-pi-docker-install [2018/03/13 19:29]
Elco Jacobs [Log in on the raspberry pi with ssh]
getting-started:raspberry-pi-docker-install [2019/03/16 16:51] (current)
99.93.141.76 Changed step for updating the packages on Raspian.
Line 1: Line 1:
 ===== Installing Docker and BrewPi on a Raspberry Pi ===== ===== Installing Docker and BrewPi on a Raspberry Pi =====
-REWRITING THIS! 
  
 We run BrewPi inside a Docker container to make it easier to: We run BrewPi inside a Docker container to make it easier to:
Line 11: Line 10:
 On the Raspberry Pi, we start with the latest Raspbian image and then install Docker. Then we use Docker to deploy and run a BrewPi container. On the Raspberry Pi, we start with the latest Raspbian image and then install Docker. Then we use Docker to deploy and run a BrewPi container.
 To view and manage Docker containers, we'll also install portainer. To view and manage Docker containers, we'll also install portainer.
 +-------------
  
-==== Basic installation of Raspbian ====+==== Install ​Raspbian ====
 To get started we have to write Raspbian, the operating system for the Raspberry Pi, to an SD card. We can then boot from this SD card and log in to configure some basic settings. To get started we have to write Raspbian, the operating system for the Raspberry Pi, to an SD card. We can then boot from this SD card and log in to configure some basic settings.
  
Line 29: Line 29:
 If Etcher doesn'​t work for you, here is [[Flash SD Card from Ubuntu|an alternative guide for Ubuntu]]. If Etcher doesn'​t work for you, here is [[Flash SD Card from Ubuntu|an alternative guide for Ubuntu]].
  
-=== Making ​WiFi and SSH work at first boot ===+=== Configure ​WiFi and SSH to work at first boot ===
 To ensure that you can log in remotely over WiFi, without having to connect a monitor and keyboard, you can create 2 files on the SD card that the Pi recognizes when it boots. To ensure that you can log in remotely over WiFi, without having to connect a monitor and keyboard, you can create 2 files on the SD card that the Pi recognizes when it boots.
 After you have flashed the SD card, it should show up in your file manager as a partition named '​BOOT'​. You might have to unplug and replug your SD card for it to show up. After you have flashed the SD card, it should show up in your file manager as a partition named '​BOOT'​. You might have to unplug and replug your SD card for it to show up.
Line 55: Line 55:
 After creating these two files, it is time to put the SD card in the Raspberry Pi and power it up. It will take some time to boot for the first time. You could plug in an HDMI monitor to see the progress. After creating these two files, it is time to put the SD card in the Raspberry Pi and power it up. It will take some time to boot for the first time. You could plug in an HDMI monitor to see the progress.
  
 +-------------
 ==== Find the Raspberry Pi on your local network ==== ==== Find the Raspberry Pi on your local network ====
-It might not be necessary to find and remember the IP-address of your Raspberry Pi. It will register itself on the network as ''​rasbperrypi.local''​. This is provided by the package ''​avahi-daemon''​ and it is called Zeroconf.+It might not be necessary to find and remember the IP-address of your Raspberry Pi. It will register itself on the network as ''​raspberrypi.local''​. This is provided by the package ''​avahi-daemon''​ and it is called Zeroconf.
  
 If the .local address doesn'​t work, you can use the app Fing ([[https://​play.google.com/​store/​apps/​details?​id=com.overlook.android.fing|Android]] / [[https://​itunes.apple.com/​gb/​app/​fing-network-scanner/​id430921107|iOS]]). \\  This app can scan your local network for devices. If our Raspberry Pi successfully connected to your network, it should be on the list. Make a note of the IP address. If the .local address doesn'​t work, you can use the app Fing ([[https://​play.google.com/​store/​apps/​details?​id=com.overlook.android.fing|Android]] / [[https://​itunes.apple.com/​gb/​app/​fing-network-scanner/​id430921107|iOS]]). \\  This app can scan your local network for devices. If our Raspberry Pi successfully connected to your network, it should be on the list. Make a note of the IP address.
Line 64: Line 65:
 ==== Log in on the Raspberry Pi with ssh ==== ==== Log in on the Raspberry Pi with ssh ====
 SSH is a secure connection to a remote computer. You can use SSH to remotely login on the command line of the pi, from another system. SSH is a secure connection to a remote computer. You can use SSH to remotely login on the command line of the pi, from another system.
 +It is much easier to use SSH than to use a keyboard, because you can copy and paste the commands below, instead of typing them.
  
-=== Linux and Mac === +=== From Linux or OSX === 
-An ssh client is installed by default on any Linux or MAC system. You can use this command in a console window to connect to the pi:+An ssh client is installed by default on Linux or OSX. You can use this command in a console window to connect to the pi:
 <​code>​ <​code>​
 ssh pi@raspberrypi.local ssh pi@raspberrypi.local
Line 78: Line 80:
  
  
-=== Windows ===+=== From a Windows ​PC ===
 On Windows, you should download the ssh client [[https://​www.chiark.greenend.org.uk/​~sgtatham/​putty/​latest.html|PuTTY]]. On Windows, you should download the ssh client [[https://​www.chiark.greenend.org.uk/​~sgtatham/​putty/​latest.html|PuTTY]].
  
Line 86: Line 88:
  
  
 +==== Configure and install necessary packages ====
  
-==== Deploy the brewpi container ==== +Once logged in, run raspi-config to configure your password, locale settings and time zone:
-Get the latest raspbian based image brewpi image +
 <​code>​ <​code>​
-docker pull brewpi/​brewpi-raspbian+sudo raspi-config
 </​code>​ </​code>​
-Deploy a new brewpi container. Modify ​the command below to to your liking, especially the port and the data location ​on the host (default is ''​~/​brewpi-data''​). + 
-If you want to connect your BrewPi Spark over USB, check the section below.+Update ​the packages ​on the system:
 <​code>​ <​code>​
-docker run -d --name brewpi -p 80:80 -v ~/​brewpi-data:/​data -v /​etc/​timezone:/​etc/​timezone -v /​etc/​localtime:/​etc/​localtime --restart always brewpi/​brewpi-raspbian+sudo apt-get update && sudo apt-get dist-upgrade 
 +</​code>​ 
 + 
 +Install Docker 
 +<​code>​ 
 +curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh 
 +</​code>​ 
 + 
 +Add the pi user to the docker group, so it can run docker commands: 
 +<​code>​ 
 +sudo usermod -aG docker pi 
 +</​code>​ 
 + 
 +Reboot the system to complete the setup: 
 +<​code>​ 
 +sudo reboot 
 +</​code>​ 
 + 
 + 
 +==== Deploy the Portainer docker image ==== 
 +Portainer is a web interface to manage your Docker containers. It runs in a docker container itself. 
 +Installing portainer is easy. Log in again with SSH. Pro tip: you can repeat previous commands by using the up arrow. You can autocomplete commands and paths using tab. 
 + 
 +The command to deploy portainer is: 
 +<​code>​ 
 +docker pull portainer/​portainer 
 +docker run -d -p 9000:9000 -v /​var/​run/​docker.sock:/​var/​run/​docker.sock --restart always ​--name ​portainer portainer/​portainer -H unix:///​var/​run/​docker.sock 
 +</​code>​ 
 + 
 +Portainer will now run on port 9000. 
 +Go to [[http://​raspberrypi.local:​9000]],​ or ''​http://​[ip address]:​9000''​ in your web browser. 
 + 
 +It will ask you to set an admin password when you first access it. 
 + 
 +{{:​getting-started:​portainer-password-setup.png|}} 
 + 
 +On the container tab, you can see all the docker containers that are running. At this point, it will be only the container that runs portainer. 
 + 
 +{{:​getting-started:​portainer-running-containers.png|}} 
 + 
 +From this page, you can create, delete or recreate containers. You can also click on '​console'​ to run commands inside the container. 
 + 
 +Finally click on '​endpoints'​ in the left menu. Click on the only endpoint which is called '​primary'​ or '​local'​. In the public IP field, enter ''​raspberrypi.local''​ or the IP address of the pi. 
 +If you omit this step, clicking on exposed ports of a container will link to 0.0.0.0:80 instead of raspberrypi.local:​80,​ which will not work. 
 + 
 + 
 +==== Deploy the BrewPi container ==== 
 +Now we are ready to deploy a BrewPi container. This container will run the BrewPi web interface and the BrewPi Python script that communicates with the BrewPi Spark. 
 + 
 +The container will store your brewing data and settings outside of the container, so you can safely delete and recreate the container without losing data. 
 +This is done by creating a mapped volume. In the command below, the ~/brewpi-data on the raspberry pi host is mapped to /data in the container. 
 + 
 +The container is started with -d, so it runs as a daemon in the background. If you run into trouble, omit -d to see where it errors. 
 + 
 +The container exposes 2 ports, port 80 and port 81. 
 +The only difference is that port 81 asks for a username and password. 
 + 
 +If you want to forward a port on your router, so you can access it from outside of your home network, only forward port 81. 
 + 
 + 
 +<​code>​ 
 +docker pull brewpi/​brewpi-raspbian 
 +docker run -d --name brewpi --privileged ​-p 80:80 -p 81:81 -v ~/​brewpi-data:/​data -v /​etc/​timezone:/​etc/​timezone -v /​etc/​localtime:/​etc/​localtime --restart always brewpi/​brewpi-raspbian
 </​code>​ </​code>​
  
Line 103: Line 167:
 | <​code>​-d</​code> ​                                                              | After starting the container, run it as daemon in the background. ​                                                         | | <​code>​-d</​code> ​                                                              | After starting the container, run it as daemon in the background. ​                                                         |
 | <​code>​--name brewpi</​code> ​                                                   | Name the new container brewpi, modify this you are running multiple brewpi containers. ​                                    | | <​code>​--name brewpi</​code> ​                                                   | Name the new container brewpi, modify this you are running multiple brewpi containers. ​                                    |
-| <​code>​-p 80:​80</​code> ​                                                        | Map port 80 of the container to port 80 of the host. <br> If port 80 is in use, use a differnt ​port, for example 8000:​80. ​ |+| <​code>​--privileged</​code> ​                                                    | Run with elevated permissions to access serial ports that are present when the container starts. ​                         | 
 +| <​code>​-p 80:​80</​code> ​                                                        | Map port 80 of the container to port 80 of the host. <br> If port 80 is in use, use a different ​port, for example 8000:​80. ​
 +| <​code>​-p 81:​81</​code> ​                                                        | Map port 81 of the container to port 81 of the host.                                                                       |
 | <​code>​-v ~/​brewpi-data:/​data</​code> ​                                          | Store data and settings in ~/​brewpi-data on the host.                                                                      | | <​code>​-v ~/​brewpi-data:/​data</​code> ​                                          | Store data and settings in ~/​brewpi-data on the host.                                                                      |
-| <​code>​-v /​etc/​timezone:/​etc/​timezone -v /​etc/​localtime:/​etc/​localtime</​code> ​ | Use timezone from the host.                                                                                                |+| <​code>​-v /​etc/​timezone:/​etc/​timezone -v /​etc/​localtime:/​etc/​localtime</​code> ​ | Use timezone ​and time from the host.                                                                                       ​|
 | <​code>​--restart always</​code> ​                                                | Start on boot and always restart the container when it stops. ​                                                             | | <​code>​--restart always</​code> ​                                                | Start on boot and always restart the container when it stops. ​                                                             |
 | <​code>​brewpi/​brewpi-raspbian</​code> ​                                          | The image that is used. Use''​brewpi/​brewpi-raspbian''​ for the raspberry pi, ''​brewpi/​brewpi-ubuntu''​ for x64/x86 systems. ​ | | <​code>​brewpi/​brewpi-raspbian</​code> ​                                          | The image that is used. Use''​brewpi/​brewpi-raspbian''​ for the raspberry pi, ''​brewpi/​brewpi-ubuntu''​ for x64/x86 systems. ​ |
  
  
-=== Connecting ​the BrewPi Spark via USB ===+Please note that you need to have the BrewPi Spark connected ​via USB when the container starts for it to be available to the container. 
 +In the web interface, you can select the serial number (for USB) or enter the IP address of the Spark to connect.
  
-If you want to connect to the BrewPi Spark over USB, you need to pass an extra argument to the container to forward the usb device, before ​'​brewpi/​brewpi-raspbian'.+=== Change ​the password for port 81 === 
 +The default login details are username ''​brewer''​ and password ''​brewpi''​. 
 +To change the password, you can run: 
 +<​code>​ 
 +sudo apt install apache2-utils 
 +sudo htpasswd -bc ~/brewpi-data/​settings/​brewpi.htpasswd username password 
 +</​code>​ 
 +Replace ''​username''​ and ''​password'​' ​with your desired user name and password.
  
-^ Parameter ​                                       ^ Explanation ​                                                         ^ +If you run the command inside your container instead of on the host, the command should be: 
-<​code>​--device=/dev/ttyACM0:/dev/ttyACM0</​code> ​ | Make the serial port device /​dev/​ttyACM0 available in the container ​ |+<​code>​ 
 +sudo htpasswd ​-bc /data/settings/brewpi.htpasswd username password 
 +</​code>​
  
-The full command will then be:+=== Troubleshooting === 
 +If you get an error about a conflict with an existing container (see below), you can remove the old container or use another name for the new one.
 <​code>​ <​code>​
-docker ​run -d --name brewpi -p 80:80 -v ~/brewpi-data:/data -v /​etc/​timezone:/​etc/​timezone -v /​etc/​localtime:/​etc/​localtime --restart always --device=/​dev/​ttyACM0:/​dev/​ttyACM0 brewpi/​brewpi-raspbian+docker: Error response from daemon: Conflict. The container ​name /brewpi” is already in use by container “e863…”. You have to remove (or rename) that container to be able to reuse that name. 
 +See ‘docker run --help’.
 </​code>​ </​code>​
  
-Please note that you need to have the BrewPi Spark connected via USB when running this commandotherwise the ttyACM0 device will not be found.+To remove ​the existing container named '​brewpi'​run: 
 +<​code>​ 
 +docker stop brewpi 
 +docker rm brewpi 
 +</​code>​
  
-=== Connecting the BrewPi Spark via WiFi === +To view all containersrun the command below or use portainer.
- +
-This step requires that you both configure the BrewPi Spark itself and your docker instance so it can find your controller on the network. Please follow [[:​how-to-setup-wifi-on-the-brewpi-spark|this guide]] to configure both. Note that since you are running dockerexpect ​the ''​config.cfg''​ to reside in ''​~/​brewpi-data/​settings/'' ​or the folder you specified when ran your container. +
- +
-==== Install the portainer ​web interface to manage docker containers ==== +
-Portainer can make it easier to manage your running docker containersYou can install it with:+
 <​code>​ <​code>​
-docker ​run -d -p 9000:9000 -v /​var/​run/​docker.sock:/​var/​run/​docker.sock --restart always --name portainer portainer/​portainer+docker ​ps -a
 </​code>​ </​code>​
  
-==== Use portainer ​to access ​the command line of the brewpi container ​==== +==== Go to the BrewPi web interface and connect to the Spark ====
-Try to load the portainer web interface: ''​192.168.1.100:​9000''​. +
-This IP address is where your rpi lives on your network and uses port 9000. Adjust accordingly.  +
-It will ask you to set an admin password. Pick a password and set it up. Use it to log in on the next page. +
  
-{{:getting-started:​portainer-password-setup.png|}}+If you didn't change the default port, you can access the BrewPi web interface at [[http://​raspberrypi.local]].
  
-On the next pagechoose to first option ​'Manage the Docker instance where Portainer is running' and click the Connect button+Click 'Start script'​if it isn't already ​running.
  
-{{:​getting-started:​portainer-connect.png|}}+Finally, go to the maintenance panel and fill in the field for connection to let the script know where it can find your BrewPi Spark.
  
-When you have logged in, you can see your running containers. In this case, there will be a brewpi and a portainer one. If you click on the published portthis will take you to the web interface.+If you want to connect to the Spark over Wifiset the drop-down menu to 'IP address'​ and enter the IP address that is displayed on the LCD of your BrewPi Spark.
  
-{{:​getting-started:​portainer-running-containers.png|}} 
  
-If you click on the brewpi ​container, you can click on 'console' ​on the container pageThis will drop you directly to the command line of the container ​if you need it.+==== Updating ​the BrewPi ​container ​===== 
 +The easiest way to update the container is let portainer re-create it. 
 +Browse to the BrewPi container and click 'recreate'​. ​Leave 'pull latest image' ticked. 
 + 
 +If you do this, you will lose any changes ​you made inside ​the container. Only the BrewPi settings and data that are stored outside ​of the container ​are kept. 
 + 
 +You can also stop the container and create a new one before ​you delete the old container. 
 +Just make sure that each container needs to have a unique name and that running containers cannot use the same port on the host.