Hue Thief docker image

I have recently upgraded from a venv Pi to a docker NUC, so I wanted to reset my Philips Hue bulbs. The most reliable way I have found to do this is Hue Thief, but I could not find an off the shelf docker solution and had to build my own. Doing so taught me a lot about building new docker images with a Dockerfile, and I was amazed by how simple it actually turns out to be.


FROM python:3
RUN git clone
RUN pip3 install wheel
RUN pip3 install -r hue-thief/requirements.txt
# for runtime flexibility don't hard-bake the command into the image
#CMD [ "python3", "hue-thief/", "/dev/ttyUSB1" ]

# these scripts are designed to go into a folder, whose name will be used as the image name
# build an image using the layers described in the docker file
docker build -t $(basename $PWD) .

# set your device accordingly
# then create the container, run the code and remove the container on completion
docker run --rm --device=/dev/$ZHA_DEV:/dev/$ZHA_DEV -it $(basename $PWD) python hue-thief/ /dev/$ZHA_DEV
# to run diagnostics on the container with a shell use:
# docker run --rm --device=/dev/ttyUSB1:/dev/ttyUSB1 -it $(basename $PWD) bash

Put the three files into a folder on your docker host – the folder name will be used for the image name. Don’t forget that those last two need chmod +x to make them executable. Then you simple build it once and run it as many times as you need.
Don’t forget that your docker host needs internet access during the build process to download the docker base image, the github repo and the pip dependencies.

Questions welcome. Enjoy!

1 Like