问题描述
老实说,我几乎没有使用 Alpine Linux 的经验,但我喜欢它的方法,因此想要改变它.我对 Docker 也比较陌生,所以如果这是一个愚蠢"的问题,请多多包涵.
I have almost no experience with Alpine Linux, to be honest, but I like its approach and therefore want to change that. I'm also relatively new to Docker, so please bear with me if this is a "stupid" question.
我想要实现的是建立在 httpd:alpine
图像上并根据我的需要扩展 HTTPd.
What I would like to achieve is building upon the httpd:alpine
image and extending the HTTPd to my needs.
这将包括激活 mod_rewrite 模块并将自定义 .htaccess 复制到图像中.
That would include activating the mod_rewrite module and copying a custom .htaccess into the image.
这是我目前所拥有的:
FROM httpd:alpine
# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/
RUN apk update
RUN apk upgrade
RUN apk add apache2-utils
RUN a2enmod rewrite
RUN rc-service apache2 restart
我现在的问题是,我不断收到未找到 a2enmod"错误,我不知道如何解决.那可能是因为 a2enmod 是纯粹的 Debian/Ubuntu/... 东西,但我不知道激活 mod_rewrite(或任何与此相关的任何模块)的其他方法.
My issue is now, that I constantly receive an "a2enmod not found" error, which I don't know how to resolve. That might be because a2enmod is a pure Debian/Ubuntu/... thing, but I don't know any alternative way of activating mod_rewrite (or any module for that matter).
非常感谢大家的支持!
推荐答案
mod_rewrite
在 alpine 中默认随 apache 一起安装,因此无需再次安装.下面是在 Alpine 中启用 mod_rewrite
的方法:
mod_rewrite
is installed by default with apache in alpine, so no need to install it again. So here's how you enable mod_rewrite
in Alpine:
FROM httpd:alpine
# Copy .htaccess into DocumentRoot
COPY ./.htaccess /var/www/html/
RUN sed -i '/LoadModule rewrite_module/s/^#//g' /usr/local/apache2/conf/httpd.conf
RUN { \
echo 'IncludeOptional conf.d/*.conf'; \
} >> /usr/local/apache2/conf/httpd.conf \
&& mkdir /usr/local/apache2/conf.d
这篇关于将 mod_rewrite 添加到 Docker 镜像 httpd:alpine的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!