Change permissions of the added file to the Docker level

The Docker Best Practice Guide says:

You are strongly encouraged to use VOLUME for any mutable and / or custom parts of your image.

And by looking at the source code, for example. cpuguy83 / nagios image this can be clearly seen, since everything from nagios to apache configuration directories becomes available as volumes.

However, looking at the same image, the apache service (and cgi scripts for nagios) starts as the default nagios user. So now I am in the marinade, since I cannot figure out how to add my own configuration files, for example, to identify more hosts for monitoring nagios. I tried:

 FROM cpuguy83/nagios ADD my_custom_config.cfg /opt/nagios/etc/conf.d/ RUN chown nagios: /opt/nagios/etc/conf.d/my_custom_config.cfg CMD ["/opt/local/bin/start_nagios"] 

I build as usual and try to run it using docker run -d -p 8000:80 <image_hash> , however I get the following error:

Error: Cannot open configuration file '/opt/nagios/etc/conf.d/my_custom_config.cfg' for reading: Permission denied

And, of course, the permissions in the folder look like (whist, the apache process runs like nagios ):

 # ls -l /opt/nagios/etc/conf.d/ -rw-rw---- 1 root root 861 Jan 5 13:43 my_custom_config.cfg 

Now, the answer was earlier given (why this does not work in the Dockerfile) , but no suitable solution was found, other than "modify the original docker file."

Honestly, I think there is some basic concept here that I did not understand (since I see no reason to declare configuration directories as VOLUME or running services as nothing but root) - so I provided the Docker file as described above ( what follows Docker best practice by adding multiple volumes) is the solution / problem:

  • To change NAGIOS_USER / APACHE_RUN_USER to "root" and run everything as root?
  • To remove VOLUME declarations in a Docker file for nagios?
  • Other approaches?

How would you extend the nagios dockerfile above with your own config file?

+1
docker apache nagios
source share
1 answer

Since you add your own my_custom_config.cfg file directly to the container during assembly, simply change the permissions on the my_custom_config.cfg file on the host machine, and then create your image using docker assembly. The permissions of the host machine are copied to the container image.

0
source share

All Articles