Hi, this is probably a dumb one but I wondered if anyone could help? It’s related to using Docker on a Pi with PiicoDev sensors.
I have a Raspberry Pi 4B with some PiicoDev sensors and OLED attached. They’re all configured and work (using the standard methods of install). I have also installed Docker on my Pi and so what I am trying to do is create a couple of containers that include all the code / environment to emcompass the PiicoDev sensors, so that I can reload a container onto another Pi and kick off the code.
The method I used was to create a docker file with the following:
CMD ["python3", "PiicoDev-Container-A.py" ]
and then I build the container using
docker build -t mytestimage .
The docker build process builds fine. However, when I go to run the docker image (using
docker run mytestimage) it seems as if the python script is failing because it is unable to find the PiicoDev module(s) which make me think it hasn’t copied piicoDev runtime code into the docker container… I think this because when I issue the
docker run mytestimage command, it comes back with :
Traceback (most recent call last):
file "//PiicoDv-container-A.py", Line 2, in <module>
from PiicoDev_SSD1306 import *
ModuleNotFoundError: No module named 'PiicoDev_SSD1306'
Thus my question is does anyone know how I add/include the PiicoDev run-time code/supporting files which are probably buried in a directory somewhere, to the docker file ?
Hi @JAMES197891 - cool that you’re going down the docker rabbit hole for deployment and versioning
I think Python on a Raspberry Pi will store its packages in
/home/pi/.local/python3.7/site-packages but don’t quote me on it
So you’d have to figure out how to add that to your image.
There’s another alternative which is to distribute the PiicoDev driver files eg.
PiicoDev_SSD1306.py in the same directory as your user-code. Then, when
import is executed, Python will start by looking in the current directory and find those files…
It feels a bit hacky, but could be super good-enough to get started!
You need to install the Piicodev modules when you build your Docker image
RUN pip install piicodev
You’ll also need to run the container with
--privileged to ensure the container has access to the i2c hardware. Hope that helps!
Nice! @Steven Thanks for sharing your Docker-fu
I suppose that guarantees a deployment of a certain version of PiicoDev - the one installed during build. The user will always have the option to upgrade afterwards / update their docker image.
Hi Michael, many thanks for the feedback, I’ll certainly give that a go later in the week when I get a chance. Thank You - and I’ll let you know how I go… once I get a working version I’ll see if I can do a write up for the community. Cheers James.
Hi Steven, Thank You also for your feedback on the docker issue I’m having. I’ll give this a go later in the week also and will let you/the community know how I go. Thank you for taking the time to respond. Cheers James.
I used Docker for my Piicodev RTC-powered NTP server, mainly because there already was a Docker image for the Chrony NTP server I could build on top of without fussing around. Also wanted something anyone else could spin up easily.
The feedback from Steven is correct. Also when starting the container you can use –privileged or use –device /dev/i2c-1
Also if your building your image on Docker.com you will need the –platform as per below:
docker run --platform linux/arm/v8 --name my_container --interactive --device /dev/i2c-1 index.docker.io/username/my_container