My Docker Stack

@Knapoc: I already checked the Dockerfile and tried to use it (i did not copy it though), but it fails when it comes to compiling.

Also: As far as I understood, Python is an interpreted language and the goal of my Docker build would be having a suitable runtime environment for my RaspberryPi3, not a compile suite.

As homeassistant should download the requirements, my current Dockerfile looks very simple:

FROM resin/raspberrypi3-python:3.6

ARG VERSION=0.65.2

RUN mkdir /config && \
    pip3 install wheel homeassistant==${VERSION}

CMD [ "python", "-m", "homeassistant", "--config", "/config" ]

Building a appropriate image is not problem, however running a container with this image fails. It looks like inside the container the required modules are not downloaded automatically. Hereā€™s an example:

INFO:homeassistant.util.package:Attempting install of sqlalchemy==1.2.2
INFO:homeassistant.setup:Setting up recorder
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: domain=recorder, service=purge>
Exception in thread Recorder:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/recorder/__init__.py", line 196, in run
    from .models import States, Events
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/recorder/models.py", line 6, in <module>
    from sqlalchemy import (
ModuleNotFoundError: No module named 'sqlalchemy'

However, if I mimic the behaviour of the official build using a requirements file and installing dependencies during Docker build - it works.

@flamingm0e good day. Couple of questions
Is there a way to prioritise container startup on boot? Basically I need the last to be HA.

Is it possible to ā€œexportā€ a command from the container? In the previous set up I had a temp sensor that was command line based. With docker the command does nothing as possibly the package is not in the HA container, but it is in the base OS (Ubuntu 18.04)

Thank you

Yes, you use the depends_on: option

Iā€™m not sure what this means.

What package? Where is this sensor connected? What is your command?

If you have something directly connected to your host, and you want to present that to your running container, you use bind mounts. You donā€™t go the other way.

Thank you,
So I would say depends-on
Mqtt, Zoneminder, etcā€¦

The sensor is the cpu temp from the lm sensors Ćŗtil in Ubuntu.
Before docker I had a command line sensor as ā€œsensorsā€ and with a value template I got the number.

In docker that command doesnā€™t work

This wonā€™t work in Docker without a lot of effort.

You could utilize SNMP or write a simple script that outputs the data to a txt file and you read that from your HA instance.

Ok thank you.
On docker compose, how is it automatically started on boot?

Thank you for your help.
After reading your post last weekend I spent 2 entire days learning and setting it up and itā€™s great.
Incorporated portainer in panel frame so upgrade is one click from within the HA browser.
Set up watchtower etc, really pleased with the way it all works and I really appreciate the fact that if I break something I just kill it and start again with 2 clicks.
Has its quirks like this sensor, but thereā€™s a way around as you pointed.
One thing really concerned me was the countless complaints about zwave set up. In my case of course it didnā€™t work right away, but after a bit of reading got it going.
Thank you again

I used this which I used it on my RPI and it works on my NUC Homeassistant docker.

sensor:
 - platform: command_line
   name: "Temperature CPU"
   command: "cat /sys/class/thermal/thermal_zone0/temp"
   unit_of_measurement: "Ā°C"
   value_template: '{{ (value | multiply(0.001)) | round(1) }}'
2 Likes

thank you. Will give it a try.

For your portainer container you can also add to your compose file:

command: --no-auth -H unix:///var/run/docker.sock --no-analytics

Then you donā€™t need persistent storage. Though this will completely open up portainer so I would suggest you have it behind something else doing auth.

1 Like

Iā€™m using cloudflare acccess for my domains, much more secure I believe than simple auth

You seem to know your onions when it comes to all this, so hoping you could help :grinning:

Iā€™ve managed to setup a reverse proxy to route a DuckDNS domain via https to Home Assistant running in a Docker container, using traefik.

Do you know if itā€™s possible to also access it locally via the IP address, or the machine name (192.168.0.5:8123 or my-server.local) as well as the external domain name? (MY-DOMAIN.duckdns.org).

I thought I read that this was possible somewhere, but maybe I was wrong, or itā€™s only possible with nginx?

I can post my docker-compose.yml and traefik.toml code if it helps.

This is a great idea for a post and thank you so much for taking the time to do this. I have been wanting to get into Docker for a while but have never had the time. I may take a closer look at this later tonight :slight_smile:
John

EXECUTING COMMAND LINE FROM WITHIN HOMEASSISTANT CONTAINER:

https://hastebin.com/sojasolite.sql

Wanted to share this bit of work with other docker ā€œnew convertsā€ such as myself.

1 Like

Hass anyone created a custom docker image? say you wanted a few extra python scripts / libs runningā€¦ and you normally would have to go into docker interactive and then do a PIP3 installā€¦ ā€¦ however iā€™m looking to build my own docker imageā€¦ sorta a forkā€¦anyone know how to do thatā€¦

I want to take the base imageā€¦so its updated by the hassbian teamā€¦ but then re-run my scripts ontop of it everytime there is a update to the base;ā€¦so then i have a new docker image to use.

@flamingm0e so this would take the existing docker image i assume?

i was also considering ā€¦https://github.com/home-assistant/pi-gen but not sure if thatā€™s the current way the hassbian raspi docker image is made.

i was assuming i needed hassbianā€™s docker file first ā€¦then add on my changes to itā€¦ ?

when you create a dockerfile, you can point it to any docker image you like to build from.

It will take the Docker image and overlay your changes on top to create a new image.

Only if you are using hassbian docker?