RPI - Appdaemon/Docker/Docker-Compose/Portainer Install - WIP

I left HA a while back and recently needed it for another project. I’ve always run supervisor in the past and didn’t really see the point of docker for HA.
Looking at videos online really didn’t cover docker vs supervisors and those who like the docker seem to miss the point of why so many love supervised. Not to mention the number of middle age men who are decking out their homes with purple led mood lighting is a bit of a concern :sweat_smile:

With that said this is a WIP, which needs some tweaks, but the end result should leave you with a docker install that uses docker-compose and portainer. Think of it as a list of compiled google searches…

Docker Setup

Standard update

sudo apt-get update && sudo apt-get upgrade

Docker

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

if that doesnt work you can also run:

curl -fsSL test.docker.com -o get-docker.sh && sh get-docker.sh

Give user account access to Docker - replace pi with user name

  • The syntax for adding users to the Docker group is:

sudo usermod -aG docker pi

  • To add the permissions to the current user run:

sudo usermod -aG docker ${USER}

  • check if it is running:

groups ${USER}

Docker Compose

You need libffi-dev, libssl-dev, pip3/py3 so if you dont run:


sudo apt-get install libffi-dev libssl-dev

sudo apt install python3-dev

sudo apt-get install -y python3 python3-pip

install docker composer via pip:

sudo pip3 install docker-compose

Enable auto boot of docker composer:

sudo systemctl enable docker

Portainer

create a docker-compose file in the directry you plan to work from i.e.

sudo nano docker-compose.yaml

add to the file - noting if you working out of VS code you can chnage the permissions to allow alter content via the window i.e. sudo chmod a+rwx <filename> of sudo chmod -R a+rwx <foldername> you don’t have to but it saves doing it directly out of terminal


version: '3.0'

services:

  portainer:

    container_name: portainer

    image: portainer/portainer-ce

    restart: always

    ports:

      - "9000:9000/tcp"

    environment:

      - TZ=Europe/London

    volumes:

      - /var/run/docker.sock:/var/run/docker.sock

      - /opt/portainer:/data

Save i.e. crtrl+s and crtl+X

Run the docker-compose command:

sudo docker-compose up -d

At this point you should be able to access portainer via a web browser:

http://:9000/

Create a new user and password - these can be anything

If you are prompted with the quick setup select - get started to start a locally

Adding Home Assistant

Either in terminal or VSCode

i.e. if terminal sudo nano docker-compose.yaml

if VSCode just find the file you created earlier

and add:


homeassistant:

    container_name: homeassistant

    image: "ghcr.io/home-assistant/home-assistant:stable"

    volumes:

      - /opt/homeassistant/config:/config

      - /etc/localtime:/etc/localtime:ro

    env_file:

      - .env

    restart: unless-stopped

    privileged: true

    network_mode: host

Save i.e. crtrl+s and crtl+X

be careful to ensure tabbing is correct. a yaml extention helps with this.

re run the docker-compose command:

sudo docker-compose up -d

This part is like a typical HA install meaning give it some time so check on a browser periodically:

http://:8123/

Complete HA setup via the web browser

** If you access portainer via browser you can also check the containers - in here you will see what has been installed, access logs, etc… this becomes a pain so adding a IFRAME becomes a good option to access it directly from your dash board.

Adding IFRAME/AppDaemon/.env

massive caviate you don’t need to add envrioment variables but if you want to run a dynamic system its worth the couple of extra steps…

To do this we need a few things

  1. Access Token for Appdaemon - skip this is not installing AD

  2. .env file for the configuration.yaml

  3. .env file for the dockercompose.yaml

  4. To get a AD Token log in to HA and naviagte to

Your Profile and scroll down to ‘Long-Lived Access Tokens’ Create token naming it what ever you want i.e. Appdaemon copy this for the next step.

** If you don’t copy it don’t stress just delete and create a new one.

within your HA DIR that has the configuration.yaml i.e /opt/homeassistant/config

sudo nano .env


IFRAME_URL=http://${SERVER_IP}:9000/#/containers

source .env

within the DIR that contains your docker-compose.yaml

sudo nano .env

then add (replace the access token with the one you generate)


PORT5050=http://${SERVER_IP}:5050

PORT8123=http://${SERVER_IP}:8123

ADTOKEN=<ADD YOUR ACCESS TOKEN>

source .env

to check echo "IFRAME_URL is: $IFRAME_URL"

cd

Next we are going to add a few lines to the bottom of bashrc file to set up the enviroment SERVER_IP to equal the rpi IP

sudo nano ~/.bashrc

Add to the bottom


source /opt/.env

export SERVER_IP=$(hostname -I | awk '{print $1}')

Save i.e. crtrl+s and crtl+X

back at the docker-compose add the appdaemon:


  appdaemon:

    container_name: appdaemon

    restart: unless-stopped

    image: acockburn/appdaemon:latest

    environment:

      HA_URL: ${PORT8123}

      TOKEN: ${ADTOKEN}

      DASH_URL: ${PORT5050}

    ports:

      - "5050:5050"

    volumes:

      - /opt/appdaemon:/conf

      - /var/run/dbus:/var/run/dbus #This is only needed if wanting to use Bluetooth, can delete otherwise

    env_file:

      - ../ioc-hub/.env

    depends_on:

      - homeassistant

Next find your HA configuration.yaml file and add:


panel_iframe:

  portainer:

    title: "Portainer"

    url: !env_var IFRAME_URL

    icon: mdi:docker

    require_admin: true

Next add the following to the secrets.yaml file. it should be in the same DIR:

IFRAMEURL: !env_var IFRAME_URL

restart docker-compose with a .env as per environment variables - Docker-compose env file not working - Stack Overflow

docker-compose --env-file .env up -d

sudo reboot

Now when you run echo $SERVER_IP it should return the IP of you pi… if it doesn’t www.google.com

Notes on Appdaemon if you need to include libaries i.e. bleak inlcude a requirements.txt inside the same DIR as the appdaemon.yaml file and reload appdaemon i.e.

bleak==0.19.5

Sources:

Yes! Well said.

1 Like