操作“-D FOREGROUND”失败。使用 docker 构建 apache2 映像时
Action '-D FOREGROUND' failed. while building apache2 image with docker
我正在尝试使用 apache 配置构建 apache 映像,它将设置虚拟主机并最终将所有非静态请求重定向到 Unicorn。但是在构建图像时失败并出现错误。操作“-D FOREGROUND”失败
我为此遵循了一个教程,并在我的 apache2.conf 文件
中添加了下面的虚拟主机
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot /var/www/app/public
RewriteEngine On
# Redirect all non-static requests to unicorn
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RewriteCond %{DOCUMENT_ROOT}/public/[=11=] -f
RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/[=11=] [L]
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:3000
</Proxy>
ProxyPass / balancer://unicornservers/
ProxyPassReverse / balancer://unicornservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
和 docker 用于 apache 映像的文件
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y apache2
RUN apt-get install -y apache2-utils
EXPOSE 80
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
ENV APACHE_SERVER_NAME localhost
ENV RAILS_ROOT /var/www/app
WORKDIR $RAILS_ROOT
COPY public public/
RUN a2enmod proxy
RUN a2enmod proxy_balancer
RUN a2enmod proxy_http
RUN a2enmod rewrite
RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod proxy_html
COPY config/containers/web/apache2.conf /etc/apache2
COPY config/containers/web/ssl /etc/apache2/ssl/
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
CMD 命令在图像内部执行,如果图像本身没有作为前台进程启动,这将不会实现任何效果。
您可能希望以类似以下内容开始图像:
docker run -it YOUR_APACHE_IMAGE_HERE
-i -t
选项将按照 here
所述以交互式终端模式启动图像
通过在 Dockerfile 中启用模块 mod_lbmethod_byrequests 找到解决方案。
运行 a2enmod lbmethod_byrequests
这在 Apache 2.2.22 中不是必需的,但 Apache 2.4 是必需的
我必须在末尾添加以下行才能使其正常工作
ENTRYPOINT ["tail", "-f", "/dev/null"]
我正在尝试使用 apache 配置构建 apache 映像,它将设置虚拟主机并最终将所有非静态请求重定向到 Unicorn。但是在构建图像时失败并出现错误。操作“-D FOREGROUND”失败
我为此遵循了一个教程,并在我的 apache2.conf 文件
中添加了下面的虚拟主机<VirtualHost *:80>
ServerName test.example.com
DocumentRoot /var/www/app/public
RewriteEngine On
# Redirect all non-static requests to unicorn
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L]
RewriteCond %{DOCUMENT_ROOT}/public/[=11=] -f
RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/[=11=] [L]
<Proxy balancer://unicornservers>
BalancerMember http://127.0.0.1:3000
</Proxy>
ProxyPass / balancer://unicornservers/
ProxyPassReverse / balancer://unicornservers/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
和 docker 用于 apache 映像的文件
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y apache2
RUN apt-get install -y apache2-utils
EXPOSE 80
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
ENV APACHE_SERVER_NAME localhost
ENV RAILS_ROOT /var/www/app
WORKDIR $RAILS_ROOT
COPY public public/
RUN a2enmod proxy
RUN a2enmod proxy_balancer
RUN a2enmod proxy_http
RUN a2enmod rewrite
RUN a2enmod ssl
RUN a2enmod headers
RUN a2enmod proxy_html
COPY config/containers/web/apache2.conf /etc/apache2
COPY config/containers/web/ssl /etc/apache2/ssl/
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
CMD 命令在图像内部执行,如果图像本身没有作为前台进程启动,这将不会实现任何效果。
您可能希望以类似以下内容开始图像:
docker run -it YOUR_APACHE_IMAGE_HERE
-i -t
选项将按照 here
通过在 Dockerfile 中启用模块 mod_lbmethod_byrequests 找到解决方案。
运行 a2enmod lbmethod_byrequests
这在 Apache 2.2.22 中不是必需的,但 Apache 2.4 是必需的
我必须在末尾添加以下行才能使其正常工作
ENTRYPOINT ["tail", "-f", "/dev/null"]