在码头运行apache [英] running apache in docker

查看:162
本文介绍了在码头运行apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经用尽了所有的线程和文章,但是仍然无法让我的apache网络服务器在Centos Docker Container上以独立模式运行。



这是我的简化Dockerfile

 #install apache 
运行yum -y安装httpd

#启动webserver
ADD startservice / startservice
运行chmod 775 / startservice

EXPOSE 80

CMD [/ startservice]

我的明星服务脚本只有

 #/ usr / bin / sh 
服务httpd开始

我可以建立罚款,但是,似乎无法以守护进程/独立模式运行容器。我如何做?



我正在使用它来以独立模式运行容器

  docker run -p 80:80 -d -t webserver 

我必须登录到容器并启动该服务以使Web服务器运行。

  docker run -p 80:80 -i -t webserver bash 
服务httpd开始


解决方案

这是一个经典码头问题。您启动的过程必须在前台执行,否则容器就会停止。



所以,为了能够这样做,可以在startservice脚本中使用以下内容: / p>

 #!/ usr / bin / sh 
服务httpd开始

#尾随日志文件
tail -f / var / log / httpd / access_log

#或者,您可以拖尾任何文件,甚至/ dev / null
#tail -f / dev / null

请注意,还有其他修复方法。一种方法是使用 supervisord 来保持流程的有效性。超级管道方法比 tail -f -approach更干净,更简洁,我个人更喜欢替代方案。



另一个选择就是您不要将httpd作为服务启动,而是提供 -DFOREGROUND 参数。这将使httpd被附加到shell(而不是fork到后台进程)。

  / usr / sbin / httpd有关http在前台模式下的更多信息,请检查这个疑问


Ok, I have exhausted pretty much all threads and articles, but still cant get my apache webserver to run in standalone mode on Centos Docker Container.

Here is my simplified Dockerfile

# install apache
RUN yum -y install httpd

# start the webserver
ADD startservice /startservice
RUN chmod 775 /startservice

EXPOSE 80

CMD ["/startservice"]

My starservice script just has

#!/usr/bin/sh
service httpd start

I can build fine, but, cant seem to run the container in daemon/standalone mode. How do I do that?

I am using this to run the container in standalone mode

docker run -p 80:80 -d -t webserver

I have to log onto the container and start the service for the webserver to run.

docker run -p 80:80 -i -t webserver bash
service httpd start

解决方案

This is a classic docker issue. The process you start must execute in the foreground, otherwise the container simply stops.

So, to be able to do so the following can be used in your startservice script:

#!/usr/bin/sh
service httpd start

# Tail the log file
tail -f /var/log/httpd/access_log 

# Alternatively, you can tail any file or even /dev/null
#tail -f /dev/null

Note that there are also other ways of fixing this. One way is to use supervisord that keeps your processes alive. The supervisord-approach is cleaner and les hackish than the tail -f-approach and I would personally prefer that alternative.

Another alternative is simply that you do not start httpd as a service but instead provide the -DFOREGROUND parameter. This will make httpd be attached to the shell (and not fork off to a background process).

/usr/sbin/httpd -DFOREGROUND

For more info on http in foreground mode, check this question.

这篇关于在码头运行apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆