Hello,
I want to use the I2C device in Docker Container. (My Device is RaspberryPi3)
When I using RUN modprobe i2c-dev, is failing to start with the following error message: modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.15.32-v7l+
My full Dockerfile:
FROM balenalib/raspberrypi3-python:3.7-latest
ENV PYTHONUNBUFFERED
RUN pip install -r ./requirements.txt
CMD modprobe i2c-dev && python /app/app.py
All input much appreciated, thanks!
Hi, as per the docs, after your first push, the code will most likely throw an error caused by the modules not being loaded. If this is the case, simply reboot the pi and the modules should be loaded. Please refer this. Hereās a neat example for your reference : https://github.com/balena-io-playground/balena-rpi-py-AD , I hope that helps.
Hi @iayanpahwa ,
Thanks for checking in.
I try to reboot my raspberrypi3 and run again the image, but i got the same error.
I try the two thing forward:
1. Run modprobe i2c-dev in docker Container (Run exec)
modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.15.32-v7l+
2. Run modprobe i2c-dev in Raspberry PI 3 ā is work
I read the /etc/modules, as shown below:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with ā#ā are ignored.
i2c-dev
I just tried this on my own device.
Assuming: freshly flashed pi3, balenaOS 2.98.33, local development mode.
First I got an error about the copied Dockerfile, saying that ENV PYTHONUNBUFFERED requires a value.
To prevent this, and any pip issues, I changed the Dockerfile to its minimal form:
FROM balenalib/raspberrypi3-python:3.7-latest
CMD balena-idle
Logging in through ssh and running lsmod | grep i2 shows the driver is already loaded.
Disabling local mode and switching the device to production mode didnāt change this.
Changing the Dockerfile to CMD modprobe i2c-dev && balena-idle likewise didnāt cause any issues.
Can you share which OS version youāre running and what your device configuration looks like?
Hi @TJvV ,
Thanks for checking in.
Sorry I loss the value in dockerfile. (ENV PYTHONUNBUFFERED 1)
I install the docker in raspberrypi, and run docker container using belena os.
When I run the belena container, I got the error message.
(modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.15.32-v7l+)
My full Dockerfile:
FROM balenalib/raspberrypi3-python:3.7-latest
ENV PYTHONUNBUFFERED 1
RUN pip install -r ./requirements.txt
CMD modprobe i2c-dev && python /app/app.py
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1
# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16
# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2
# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4
# uncomment for composite PAL
#sdtv_mode=2
#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800
# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18
# Additional overlays and parameters are documented /boot/overlays/README
# Enable audio (loads snd_bcm2835)
dtparam=audio=on
# Automatically load overlays for detected cameras
camera_auto_detect=1
# Automatically load overlays for detected DSI displays
display_auto_detect=1
# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2
# Disable compensation for displays with overscan
disable_overscan=1
[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1
It seems this happens when you run the balena image on a Raspbian OS rather than on Balena OS.
thijs@tjvv-pi3:~/balena/i2c-dev $ docker build -t balena_i2c .
[...]
thijs@tjvv-pi3:~/balena/i2c-dev $ docker run -it --rm balena_i2c /bin/bash
root@7e86e7842b42:/# modprobe i2c-dev
modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.15.32-v7+
root@7e86e7842b42:/#
The problem has to do with some things the balena engine does, that docker doesnāt.
Specifically, balena engine will treat a single service deployment as privileged, and will use certain tags to configure extra things for your container, like mounting devices and modules.
In this specific case, I made it work by using the following command to run the image:
Hi @ianw, if your application is using a docker compose file you will need to include the io.balena.features.kernel-modules label so the supervisor mounts the /lib/modules directory in the container so that it is accessible to modprobe.
I am trying to get this to work (I canāt tell if the OP was able to). I followed everything in this thread. As per your example, I have my Dockerfile at the bare minimum. Same balenalib image. I can also ssh in and run lsmod | grep i2 to find the drivers are loaded. However when I add modprobe i2c-dev to the CMD I still receive
modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.15.34-v8
This is on a pi4 with a fresh BalenaOS v2.108.18+rev2 burn.
Iām using a docker-compose file which is below. config.txt was also modified to enable i2c as per the OPās comments
If someone can spot what I am missing I would be really grateful!
Iād be happy to look into this tonight or tomorrow.
Can you post your full config.txt, Dockerfile and docker-compose.yml as preformatted text (rather than blockquote)?
That would make it easier for me to reproduce your situation.
Hello TJvV, thanks for the quick response. The files are here.
On a related note, I read that balena by default enables SPI protocol on a pi. Is this correct?
Thank you config.txt (35.5 KB) docker-compose.txt (365 Bytes) Dockerfile.txt (222 Bytes)
My bad in copy pasting; was testing with the firmware label to see if that one did mount when the modules didnāt
Iāve edited the post so the correct answer stands