Use vcgencmd within a docker node-red container

I have node-red docker container running on my Pi4B and configured several dashboards successfully. For showing the raspberry temperature usually the vcgencmd is used. Directly under the Pi that works out of the box, but in the container the vcgencmd cannot be found.

Following the description for node-red-contrib-vcgencmd under 'Usage via Docker' several setups need to be configured in order to use the vcgencmd.

I've done all that, but vcgencmd can still not be found !?

/dev/vchiq exist and I can retrieve information out of it:

>$ cat /dev/vchiq
...

If I attach a shell to the container and change into the /opt/vc/bin folder, it shows the vcgencmd. But executing it gives an error:

>$ vcgencmd measure_temp
sh: vcgencmd: not found

What does this mean ?
Does anybody has an idea ?

Many thanks

Try /opt/vc/bin/vcgencmd
If that works then it is just that the folder is not in the path.

bash-5.0# /opt/vc/bin/vcgencmd
bash: /opt/vc/bin/vcgencmd: No such file or directory

Adding folder to PATH doesn't change this.

What does this give

cd /opt/vc/bin
ls -l

Trim it if necessary to show what it says about vcgencmd
Then if it shows the command
./vcgencmd measure_temp
Note the dot slash at the start.

>$ ls -la
...
-rwxr-xr-x    1 root     root         75508 Feb  5 16:25 raspiyuv
-rwxr-xr-x    1 root     root         74068 Jun 24  2019 tvservice
-rwxr-xr-x    1 root     root        257820 Jan 20 14:44 vcdbg
-rwxr-xr-x    1 root     root         15192 Aug 19  2019 vcgencmd
-rwxr-xr-x    1 root     root         69068 Jun 24  2019 vchiq_test
-rwxr-xr-x    1 root     root          7824 Jun 24  2019 vcmailbox
-rwxr-xr-x    1 root     root         15160 Jun 24  2019 vcsmem
bash-5.0#
bash-5.0# cd /opt/vc/bin/
bash-5.0# ./vcgencmd measure_temp
bash: ./vcgencmd: No such file or directory

That's really disappointing ... :face_with_raised_eyebrow: :thinking: :pensive:

... and I just noticed the node indicates 'not supported'
image

@DannyBoyKN,
I have added that feature at the time being, as it was requested in this issue. Perhaps if @mikeS7 is reading this discussion, he might be able to help you. I don't use this in Docker myself!

The error must mean that vcgencmd cannot find a file.

Could you please share full docker run command

1 Like

It's a compose file:

version: '3.6'
services:
  nodered:
    image: ctmagazin/ctnodered:latest
  ports:
    - "1880:1880"
  volumes:
    - ./data/nodered:/data
    - ./data/nodered:/usr/src/node-red/node-red-static/
    - /etc/localtime:/etc/localtime
    - /opt/vc:/opt/vc:ro
  devices:
    - /dev/vchiq:/dev/vchiq
  privileged: true
  cap_add:
    - SYS_ADMIN
    - NET_ADMIN
  restart: always
  network_mode: "host"
  environment:
    - TZ=Europe/Berlin
    - LD_LIBRARY_PATH=/opt/vc/lib

Checked right now, confirmed it doesn't work. It was in time when Node-RED image was based on debian linux. I solved it by using custom image with following in Dockerfile:

USER    root
RUN     apk add --no-cache raspberrypi
USER    node-red

You don't need to use volume mapping in such case.

PS Later I will create PR or open an issue.

There seem to be some objects missing:

>$ bash-5.0$ ldd /opt/vc/bin/vcgencmd
        /lib/ld-linux-armhf.so.3 (0xb6ee0000)
        libvchiq_arm.so => /opt/vc/lib/libvchiq_arm.so (0xb6eca000)
        libvcos.so => /opt/vc/lib/libvcos.so (0xb6eb1000)
        libpthread.so.0 => /lib/ld-linux-armhf.so.3 (0xb6ee0000)
        libdl.so.2 => /lib/ld-linux-armhf.so.3 (0xb6ee0000)
        librt.so.1 => /lib/ld-linux-armhf.so.3 (0xb6ee0000)
        libc.so.6 => /lib/ld-linux-armhf.so.3 (0xb6ee0000)
Error relocating /opt/vc/lib/libvcos.so: backtrace_symbols: symbol not found
Error relocating /opt/vc/lib/libvcos.so: backtrace: symbol not found
Error relocating /opt/vc/lib/libvcos.so: mtrace: symbol not found

Perhaps you might want to reconsider the use of docker for node-red on a Pi ?

1 Like

Or run a single bash command on the host outside to mqtt publish the data somewhere you can get it more easily...

while :; do mosquitto_pub -h localhost -p 1883 -t temperature -m $(vcgencmd measure_temp); sleep 10; done

@mikeS7: What does this mean ?
Do I have to adapt something ?
Is there a problem with the base image ?
Do I have to wait for changes ?

@DannyBoyKN
You have different Linux distributions in a host and in a container.
You should build your own image, in your case Dockerfile will looks like:

FROM    ctmagazin/ctnodered:latest

RUN     apk add --no-cache raspberrypi

you should remove - /opt/vc:/opt/vc:ro from compose file

Well, yes. The container is based on Alpine 3.11 and the Pi4B is running debian buster ...

However, I removed the volume mapping and rebuild the container from the Dockerfile by adding as you wroteapk add --no-cache raspberrypi and restarted the container with no luck :frowning:

By attaching a bash into the container and did manually:

>$ su
>$ apk add --no-cache raspberrypi
>$ exit

it works :sweat_smile:... of course it's temporary.

@DannyBoyKN
You can't rebuild container, you should build image and use it in your compose file.

Well, acc. the tutorial it is rebuilding with docker-compose up --build -d, I just tested it.
I modified my Dockerfile acc. your suggestion and will retry ..
Many thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.