1

I am running a docker container on Raspberry Pi 3 and I am trying to read from an I2C device from the container. When I use i2cdetect inside docker I can see the devices. The run option I use is sudo docker run --device /dev/i2c-1 --name <name> <image>, but when I try to read from the I2C device all CRC checks fail as if the file /dev/i2c-1 didn't mount correctly. It looks like the directory has just been copied on run and did not bind. Has anyone else experienced this?

I have also tried the --privileged option and binding the folder -v -v /dev:/dev.

I can't use i2cget to test the device because it uses 16bit addressing

I use the wiringPi library for C https://github.com/WiringPi/WiringPi.

On run I get these messages:

backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:103:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:106:systemd Bus Proxy,,,:/run/systemd:/bin/false
_apt:x:104:65534::/nonexistent:/bin/false

Output from i2cdetect -y 1 in docker:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --
  • 1
    Could you add some relevant info? Like the output of i2cdetect inside docker, and then errors when you read (can't you use i2cget to begin and eliminate yet another unknown - your software). – domen Jan 13 at 11:15
  • 1
    0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 70: 70 -- -- -- -- -- -- -- this is the output from docker with i2cdetect -y 1, I can't use i2cget to test the device because it uses 16bit addressing – Victor Timofei Jan 13 at 11:31
  • 1
    Edit your original post with additional info. – domen Jan 13 at 11:33
  • I don't think binding /dev is going to be useful. Bind mounts as far as I've noticed are about storage, but /dev/ is not that (it's not actually on the SD card either -- I would have guessed you'd end up with an empty directory, with possibly some dud in-name-only copies that ended up that at some point). OTOH, some quick googling implied it might work at least for some things... Although another possibility is that the bound mount is actually hidden behind a subsequently mounted devtmpfs in the container. – goldilocks Jan 13 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.