Action '-D FOREGROUND' failed. while build

2019-09-03 15:27发布

I'm trying to build apache image , with apache config which will set up a Virtual host and eventually will Redirect all non-static requests to Unicorn. But while building the image it's failing with the error.Action '-D FOREGROUND' failed

i followed a tutorial for this purpose and added the virtual host below in my apache2.conf file

<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/$0 -f
  RewriteRule ^.+\.(jpg|jpeg|gif|png|ico|css|js|swf)$ /public/$0 [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>

And docker file for apache image

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"]

3条回答
爷的心禁止访问
2楼-- · 2019-09-03 16:08

Found the solution for this by enabling the module mod_lbmethod_byrequests in Dockerfile.

RUN a2enmod lbmethod_byrequests

This wasn't required in Apache 2.2.22, but is required by Apache 2.4

查看更多
ら.Afraid
3楼-- · 2019-09-03 16:10

the CMD command is performed inside the image and if the image itself is not started as a foreground process this will not achieve anything.

you might want to start the image with something like:

docker run -it YOUR_APACHE_IMAGE_HERE

The -i -t options will start the image in interactive terminal mode as described here

查看更多
SAY GOODBYE
4楼-- · 2019-09-03 16:15

I have to add following line at end to make it work

ENTRYPOINT ["tail", "-f", "/dev/null"]
查看更多
登录 后发表回答