CentOS / CentOS-Dockerfiles

Dockerfiles for various common implementations
GNU General Public License v2.0
1.86k stars 1.25k forks source link

How to add EnvironmentFile directive to httpd? #70

Open nalipaz opened 8 years ago

nalipaz commented 8 years ago

I asked this on stackoverflow, but since this is the image I am using and it doesn't yet seem to be documented I thought I might ask here. http://stackoverflow.com/questions/37366257/how-to-add-environmentfile-directive-to-systemctl-using-docker-with-centos7-http

Basically I am doing:

FROM centos/httpd:latest

RUN printf "HTTP_VAR1=var1-value\n\
HTTP_VAR2=var2-value"\
 >> /etc/environment

RUN mkdir /usr/lib/systemd/system/httpd.service.d &&\
 printf "[Service]\n\
EnvironmentFile=/etc/environment"\
 > /usr/lib/systemd/system/httpd.service.d/environment.conf

COPY entrypoint.sh /entrypoint.sh

Yet my environment variables are not available. Any ideas? Is this a feature opportunity? Will I need to fork this to get it working perhaps? Thanks

jperrin commented 8 years ago

The default setup for this container doesn't use systemd, so the file would never be used. You would need to fork and edit the Dockerfile so that systemd is used to initialize the container rather than the entrypoint script. You would need to do something along the lines of the following rough pseudo-code

RUN yum -y update; yum clean all; \
(cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;

INSERT-YOUR-ENV-AND-HTTPD-INSTALL-SETUP-HERE

VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]

Note that by using systemd, you'll have to mount the host's cgroups volume into the container, and possibly add capabilities or run the container with --privileged.