10

I am running a LAMP stack in docker with the help from docker-compose, and for the webserver I am using the official image from https://hub.docker.com/_/httpd. The httpd container is created by a Dockerfile:

ARG APACHE_VERSION
FROM httpd:$APACHE_VERSION
RUN apt-get update;\apt-get upgrade;\a2enmod rewrite
COPY demo.apache.conf /usr/local/apache2/conf/demo.apache.conf
RUN echo "Include /usr/local/apache2/conf/demo.apache.conf" \
    >> /usr/local/apache2/conf/httpd.conf

I am trying to enable mod_rewrite with the \a2enmod rewrite command but I get the following error during build:

/bin/sh: 1: a2enmod: not found
ERROR: Service 'apache' failed to build: The command '/bin/sh -c apt-get update;\apt-get upgrade;\a2enmod rewrite' returned a non-zero code: 127

a2enmod is failing – from my reading it's only available in a debian system and the httpd base image doesn't have it.

How can I enable mod_rewrite module for this docker official httpd image during build?

2 Answers 2

5

I ended up figuring it out. I had to enable the module in the apache .conf file by adding the line:

LoadModule rewrite_module modules/mod_rewrite.so
2
1

You don't need a2enmod to enable certain module for Docker official httpd image. All you have to do is explicitly add the module to apache.conf file. So in my case, I need to enable mode_rewrite, here's my example Dockerfile:

FROM httpd:2.4-alpine

RUN echo "LoadModule rewrite_module modules/mod_rewrite.so" >> /usr/local/apache2/conf/httpd.conf

COPY ./html/ /usr/local/apache2/htdocs/
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.