0

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?

1 Answer 1

1

It is not the commands that are missing. You can put copies of the commands into the container. Or there equivelent. What is missing is access to the information that they need.

You can add this my mounting /proc from the host, into the container. Be careful, as this will break all of the isolation. You may be able to mount it read-only, and hidepid=2. There may also be other options.

7
  • I see, I may actually (read only) mount only the files '/proc/cpuinfo', '/sys/class/thermal/thermal_zone*/temp' and '/proc/mdstat'. This will give my container enough and not too much (read only) info. Only for hddtemp I could not find a file equivalent. I'll try; but you mean to mount the '/usr/bin/hddtemp' and possibly also the HDD's themselves in the php container and try to execut it?
    – aaa
    Commented Apr 1, 2020 at 9:50
  • I've tried mounting '/proc/cpuinfo' in docker, but it would always show as 0 bytes. And I tried using a symlink from /proc/cpuinfo to the folder which is mounted in docker; but the symlink wouldn't work with docker (it's not shown in the directory when doing 'ls' from php in that folder.
    – aaa
    Commented Apr 1, 2020 at 13:36
  • You have told us that you tried something and it did not work. What did you try. Show us. Commented Apr 1, 2020 at 16:17
  • I was able to read mdstat, cpuinfo and /sys/thermal even from within docker; I'm not quite sure why. I'll attempt to get hddtemp working as well, but that'd be a bit of a different setup
    – aaa
    Commented Apr 2, 2020 at 11:59
  • Since hddtemp is a binary file, I can't just mount it to the docker folder and expect it to work. Since the other containers could run a different distribution?
    – aaa
    Commented Apr 2, 2020 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .