cara / octoprint-containers

Resin.io / Docker setup for OctoPrint on Raspberry Pi 3B/3B+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OctoPrint containers Build Status

Contents

Introduction

This is a Docker setup for OctoPrint on Raspberry Pi.
It can be run with resin.io or as Plain Docker on Raspbian.

The setup is made of 3 containers:

  • octoprint: runs the main OctoPrint application
  • webcam: runs the webcam streaming service (mjpg-streamer)
  • haproxy: exposes the above containers on http and https ports

The build will use by default the latest OctoPrint release, this can be overridden by changing the release argument in the docker-compose.yml file.

This setup will run on any Raspberry Pi, however OctoPrint recommends a Raspberry Pi 3 or 3+.

Resin.io setup

Although it may seem complex at first, resin.io allows you to install and configure OctoPrint on a Pi in a few clicks.
Also if you have multiple OctoPrint servers, they will be managed from a central place.

For additional help and nice screenshots of the resin.io interface look at Get started with Raspberry Pi 3 and Python on the resin.io site.

Install ResinOS on your Pi

  1. Create an account at resin.io and sign in
  2. Add your public SSH key to your resin.io profile
  3. On resin.io, create an "Application" for managing your Pi.
    Choose "Raspberry Pi 3" as Device Type.
  4. Add a Device to your Application.
  • Configure wifi here if your Pi is wireless.
  • Download the ResinOS image for your Pi.
  1. Follow the instructions to write the OS on your SD-Card and boot your Pi.
    After a while your Pi will appear in your Application Dashboard.
  2. If you like you can change the name of your device.

Configure your OctoPrint device

The Environment Variables menu "E(x)" allows you to add variables to configure the device for your usage.

You can add the following variables:

Name Default Description
WEBCAM_START true Start the webcam streaming at boot time.
Use false if you have no webcam or want to start it from the OctoPrint menu
WEBCAM_INPUT input_raspicam.so -fps 5 The input plugin for mjpg-streamer.
Default is for the Raspberry Pi camera, see the documentation for others.
Example for an USB webcam: input_uvc.so -d /dev/video0 -r 640x480 -fps 5.

Install the software on the Device

The device is now ready, we need to push the containers through resin.io.
The following commands need to be executed from the terminal on your local machine -- not on the Raspberry Pi!
(On Windows, use Git BASH or something similar).

Clone this repository:

$ git clone https://github.com/AmedeeBulle/octoprint-containers.git
$ cd octoprint-containers/

Add the address of your resin.io repository. This command is displayed in the top-left corner of your application dashboard on the web site and looks like:

$ git remote add resin <USERNAME>@git.resin.io:<USERNAME>/<APPNAME>.git

Push the code to resin.io:

$ git push resin master

This will trigger a build on the resin.io servers. If all goes well it will finish with a nice unicorn 🦄 ASCII art.
Your Raspberry Pi will download and run the containers automatically; after that your OctoPrint server will be ready to go!

For future updates, you simply need to pull the new code and push it back to resin.io and your device will be updated!

$ git pull origin master
$ git push resin master

Docker setup

If you do not want to use the resin.io services, you can run the exact same configuration directly on your Raspberry Pi.

Prepare the Raspberry Pi

Download and install Raspbian Stretch Lite to your Pi (Follow the instructions from the Foundation).
Although it will work with the full Desktop environment, I strongly recommend the Lite version.

As root, install git, docker and docker-compose:

# apt-get update
# apt-get install git curl python-pip
# curl -sSL https://get.docker.com | sh
# pip install docker-compose

Ensure your linux user (pi or whatever you choose) is in the docker group:

# usermod -a -G docker <YourLinuxUser>

At this point you need to completely logout and re-login to activate the new group.

From here, you don't need root access anymore.

Clone this repository:

$ git clone https://github.com/AmedeeBulle/octoprint-containers.git
$ cd octoprint-containers/

Get the containers

You have 2 options here: download the pre-build containers or re-build them.

Option 1: Download the containers

This is the easiest and fastest way. The pull command will download the containers from the Docker Hub:

$ docker-compose pull

If you are not using a Raspberry Pi 3: multiarch build does not work properly on ARM variants (See moby/moby#34875 ).
For older Raspberry Pi you need to amend the docker-compose files to pull the correct images:

$ sed -e 's/\(image:.*\)/\1:arm32v6-latest/' -i.orig docker-compose.yml

Option 2: Re-Build the containers

If for whatever reason you want to re-build the containers on your Pi, run:

$ docker-compose build

If you are not using a Raspberry Pi 3: copy the .env-distr to .env and select you Raspberry Pi version.

Configure and run the OctoPrint server

To customise your setup, create a file named .env with the environment variables described in the resin.io section. You can use the file .env-distr as template.

Important: in docker-compose.yml uncomment the following line:

      - /run/dbus:/host/run/dbus

If you don't do that, you won't be able to restart or shut down you Pi from the OctoPrint user interface.

Run the OctoPrint server:

$ docker-compose up

This will start the containers and remain attached to your terminal. If everything looks good, you can cancel it and restart the service in detached mode:

$ docker-compose up -d

This will keep he containers running, even after a reboot.

Updates

To update your setup with a newer version, get the latest code and containers and restart the service:

$ docker-compose down
$ git pull origin master
$ docker-compose pull # or build
$ docker-compose up -d

First run

For a Plain Docker setup, you know the IP address of your Pi; if you run resin.io, you will find the address in the application console.

Point your browser to the IP address of your Raspberry Pi and enjoy OctoPrint!

At first run, the haproxy container will generate a self-signed SSL certificate, so the service will be available on both http and https ports. If you want to share your printer with the world, only expose the https port...

Enjoy!

Note about persistence

All working files (configuration, G-Code, time-lapses, ...) are stored in the octoprint_vol Docker volume, so they won't disappear unless you explicitly destroy the volume.
If you really need/want to destroy the volume and re-start from scratch:

  • resin.io: select 'Purge Data' in the Device Menu
  • Plain Docker: run
docker-compose down -v

The same applies to the containers themselves: they won't be destroyed by default even if you reboot the Pi. To remove existing container and re-create them:

  • resin.io: click on the 'Restart' icon in the Device Dashboard
  • Plain Docker: run
docker-compose down
docker-compose up -d

By doing this, you will loose any change made to the code, in particular if you installed plugins you will have to re-install them (but their configuration will be preserved).

About

Resin.io / Docker setup for OctoPrint on Raspberry Pi 3B/3B+


Languages

Language:Shell 65.9%Language:Python 34.1%