It took me quite a lot of time to figure this out, but to be able to run the vcgencmd command from a container you just need to add the following options to your docker run command:
--device=/dev/vchiq -e LD_LIBRARY_PATH=/opt/vc/lib -v /opt/vc:/opt/vc:ro
1) docker run example:
$ docker run -d --name my_container --device=/dev/vchiq -e LD_LIBRARY_PATH=/opt/vc/lib -v /opt/vc:/opt/vc:ro influxdb:1.8.9
f7c847bea90edc7d56aed666ac9f6c8264d4cc0f8817862e669aac06d750e977
$ docker exec -it my_container bash
root@f7c847bea90e:/# /opt/vc/bin/vcgencmd measure_temp
temp=42.2'C
root@f7c847bea90e:/# exit
$
2) docker-compose example:
version: "3.5"
services:
telegraf:
image: influxdb:1.8.9
restart: always
volumes:
- /opt/vc:/opt/vc:ro
devices:
- "/dev/vchiq:/dev/vchiq"
environment:
- LD_LIBRARY_PATH=/opt/vc/lib
That’s it! As easy as that.
Find the post where I found this solution and its original author here: https://github.com/fchauveau/rpi-domoticz-docker#pro-tips