Adding python module to docker image

Hi All,

I’ve got Docker running on a RPi3 with Homeassistant and I need to get a python module installed to connect my Air Conditioning unit (https://github.com/sampsyo/wideq). THe module is not on PIP so i need to install manually with -e.

From what I can see a dockerfile with the lines below will do this however I’m not sure how to install/run as part of my docker-compose to build the image. Has anyone done similar? are there any guides I can follow on this?

FROM homeassistant/raspberrypi3-homeassistant:latest
RUN pip3 install -e /opt/wideq

If you put your Dockerfile in the same directory as your docker-compose.yaml and then replace the image: line with build: . you can build with docker-compose build and run as normal.

The documentation is all in the docker web site.

Thanks - I’ve made some progress however it isn’t working for me yet
I’ve created a dockerfile and built with the following command: docker build -t ha-custom .

Dockerfile:

FROM homeassistant/raspberrypi3-homeassistant:latest
RUN pip install --upgrade pip
RUN wget https://github.com/sampsyo/wideq/archive/master.zip && unzip master.zip && cd wideq-master && pip3 install -e .

There is probably a smarter way to download and install the python module however I got this successfully build the image, when i run it the python module is still not found by HA when I try and load the custom component. I feel like there is maybe a scope issue with my logic here.

I’m launching it from docker-compose with the following configuration.

docker-compose.yaml:

  homeassistant:
    container_name: homeassistant
    image: ha-custom:latest
    network_mode: "host"
    volumes:
      - /opt/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
      - /etc/letsencrypt:/etc/letsencrypt:ro
    restart: on-failure
    depends_on:
      influxdb:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8123"]
      interval: 30s
      timeout: 10s
      retries: 6

Wouldn’t it be easier to create a custom component?

The custom component i’m using needs this python module!


I am not a developer, but I am under the impression that if you declare a python module a dependency inside the custom component it will be installed at first boot.

1 Like

pip3 can download and install a zip file, so the Dockerfile can be simplified to

FROM homeassistant/home-assistant

RUN pip3 install https://github.com/sampsyo/wideq/archive/master.zip

I’m testing this on an ubuntu machine, so I have a different base, but it should work on the Pi version.

Running this seems to have wideq installed, so I’m not sure what else the problem would be.

graham@naos-kde:~
$ docker exec -it homeassistant python3
Python 3.6.7 (default, Nov 16 2018, 22:33:19) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wideq
>>> 

thanks! that works, i’ve also found i need to edit some of the config in the wideq package for it to work for my region.

Is there a way for me to pull in the file from local storage with the Dockerfile?

Yep. That’s why I was suggesting as such.

You just need to map the directory in the image to a local directory. The difficult part will be finding the config directory in the image.

FYI got this working by using the COPY file to move the local folder into the container as per below, thanks for your help!

FROM homeassistant/raspberrypi3-homeassistant:latest
RUN pip install --upgrade pip
COPY wideq /opt/wideq
RUN pip install -e /opt/wideq
1 Like