I2C inside a docker container

I am trying to use the i2c pins on a raspberry pi inside a docker container. I install all my modules using RUN but when I use the CMD to run my python program i get an error that says

Trackback (most recent call last):
file "test.py", line 124, in <module>
bus = smbus.SMBus(1)
IOError: [Errno 2] No such file or directory

If I run this on my raspberry pi and not in my container it works fine. But when I turn off my i2c pins on my raspberry pi it gives me the same error when running it. So I know it has to do with my i2c pins being activated. Does anyone know how to resolve this problem?

  • Maven install-file not effective in GitLab/Docker: “could not resolve dependencies for project”
  • Cannot login with wp-cli generated user wordpress behind reverse proxy
  • Where to install device drivers to make docker recognize the device?
  • How to connect to a docker container from outside the host (same network) [Windows]
  • Jenkins Pipeline & Docker Plugin - concurrent builds on unique agents
  • Running .Net Core in Docker in Windows Subsystem for Linux
  • connecting Docker to a cloud provider, Amazon AWS
  • How Can I install `passenger-install-nginx-module` via Dockerfile
  • How to link multiple Docker webserver containers running on different ports to different url paths?
  • How do I display output from Python application running inside Docker container?
  • Permissions error when using cli in Jboss wildfly and docker
  • How can I access Docker set Environment Variables From a Cron Job
  • One Solution collect form web for “I2C inside a docker container”

    As a security precaution, system devices are not exposed by default inside Docker containers. You can expose specific devices to your container using the --device option to docker run, as in:

    docker run --device /dev/i2c-0 --device /dev/i2c-1 myimage

    You can remove all restrictions with the --privileged flag:

    docker run --privileged myimage

    This will expose all of /dev to your container, and remove other restrictions as well (e.g., you will be able to change the network configuration in the container and mount new filesystems).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.