Enable mod_headers, Dockerfile - Apache

The following has no effect;

# Dockerfile
FROM php:7-apache

RUN apt-get update && \
 apt-get install -y libxml2-dev && \
 docker-php-ext-install soap

RUN docker-php-ext-install mysqli

# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
RUN a2enmod headers

i.e. the mod_headers module fails to load?

enter image description here

Do you know a way how to install the mod_headers module within Dockerfile ?

I tried;

CMD ["/usr/sbin/apache2", "-D",  "FOREGROUND"]

but then the container wouldn't start.

Add this to your Dockerfile:

RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/ && \
    cp /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/

That code will enable mod_rewrite and mod_headers.

Set it in Apache config file with a sed replace. Like this:

RUN sed -i 's/#LoadModule mod_headers/LoadModule mod_headers/g' /usr/local/apache2/conf/httpd.conf

You would obviously change the module name with the required module of yours... And the correct location of your httpd.conf as it might be in a different path.