I'm building a docker container that should show information on the system status on a webpage.
I have an PHP-fpm and NGINX container running. If I use shell_exec
or exec
the .sh script I made is found and executed.
However, it does not display the output of hddtemp
and (lm-)sensors
. Most likely because these do not exist in the PHP container.
What would be the proper way to fix this?
- My colleague stated that in linux, 'everything is a file', but I do not suppose I can just mount these applications in the php-fpm container and expect them to work. It also sounds quite hacky and the php-fpm container may not be the same OS, miss requirements or i'd be unable to execute the 'sensors setup'.
- Ofcourse I could run these apps on the main OS and write the results to a file every now and mount that to the container. But again; this defeats the purpose of docker?
- I suppose I could create my own version of PHP-fpm, but this would mean that I'd have to recreate this each time there is an update for php? This also sounds a bit like a hack.
So, what would be the proper way to do this (doesn't have to be any of the above).
Currently I have the following 'working solution':
(Docker compose)
php:
image: php:7-fpm
privileged: true
volumes:
- /usr/sbin/hddtemp:/usr/sbin/hddtemp
- /etc/hddtemp.db:/etc/hddtemp.db
(PHP)
var_dump(shell_exec("/usr/sbin/hddtemp /dev/sda 2>&1"));
However; in this case I have to run PHP in 'priviliged' mode in docker, I kinda feel that this is wrong, but it needs to access the diskinfo?