[docker-compose] service with "io.balena.features.kernel-modules=1" won't start

I have some strange issues with the “io.balena.features.kernel-modules=1” flag. After adding it to my docker-compose.yml the service won’t start and I don’t know what’s the issue. I added the flag as per this comment Modprobe error when trying to enable i2c on rpi - #6 by CameronDiver in order to solve the modprobe error.

modprobe: ERROR: ../libkmod/libkmod.c:586 kmod_search_moddep() could not open moddep file '/lib/modules/5.10.83-v8/modules.dep.bin'
modprobe: FATAL: Module i2c-dev not found in directory /lib/modules/5.10.83-v8

I’ve logged to host OS via ssh and tried to run balena logs <container-id> but the logs are empty.

Running balena events also didn’t help. It shows that service tries to start and then that it stops + some mount volume info. However, I can’t find out what’s the exact issue. Does any one have any pointers about how to solve this issue?

Here’s my docker-compose:

version: '2.1'

services:
  test-service:
    build:
      context: ./docker/test
      dockerfile: Dockerfile.template
    image: test-service
    pid: 'host'
    container_name: test-service
    ports:
      - '5000:5000'
    restart: 'on-failure'
    privileged: true
    command: modprobe i2c-dev && python3 test
    # command: /bin/sh -c 'if [ "$TEST_ENABLED" = "True" ]; then python3 test; fi'
    volumes:
      - data:/app/data
    # labels:
    #  io.balena.features.kernel-modules: '1'

volumes:
  data:

Another question. Any idea why the

command: /bin/sh -c 'if [ "$TEST_ENABLED" = "True" ]; then python3 test; fi'

doesn’t work? The var. is properly set (via balena env add) inside the container. Connecting to the service via ssh and running printenv I can see that TEST_ENABLED=True

Context:
Device: RPi 4
OS: balenaOS 2.94.4
Supervisor: 12.11.36

Hi-- wondering if you’ve looked into dt parameters yet? I think that’s the best practices way of enabling kernel modules such as i2c. You can do this under device configuration under the option of “Define DT parameters”. For example in your case you can add “12c=on”. You can read more here firmware/README at master · raspberrypi/firmware · GitHub hope it helps!

Thanks for the quick reply. No, I didn’t try that. I simply followed the docs I2C and Other Interfaces - Balena Documentation and then looked around the forum.

I’m gonna test your solution.

BTW any idea why this command doesn’t work on balena?

command: /bin/sh -c 'if [ "$TEST_ENABLED" = "True" ]; then python3 test; fi'

It fails on startup but works if I execute the command inside the container. Locally, on docker, it works just fine

Hi
Did you finally test the solution?

Also, when you say that the command is failing, is it giving you an error? Or is it simply not retuning anything? If it´s not returning anything it may be because the variable hasn’t been set yet.