为什么httpd容器立即退出而在Docker中没有任何错误 [英] Why httpd container exits immediately without any error in Docker

查看:222
本文介绍了为什么httpd容器立即退出而在Docker中没有任何错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手。我的Dockerfile(从教程中获得)是:

  FROM ubuntu 

ENV DEBIAN_FRONTEND非交互式

运行apt-get更新\
&& apt-get install -y --no-install-recommends apache2 \
libapache2-mod-jk
VOLUME [ / var / log / apache2]
RUN echo'ServerName localhost' >> /etc/apache2/apache2.conf
EXPOSE 80443

ENTRYPOINT [ apache2ctl,-D, FOREGROUND]

我给了 docker build -t mg:httpd apache\ 。没有错误。

 λdocker images 
存储标签图像ID大小已增加
mg httpd 262d7a4f85fc大约一个小时之前248MB

docker run -it mg:httpd



没有错误,但光标会立即返回命令提示符。在浏览器中进入 http:// localhost / 时得到无法连接

 λdocker ps -a 
容器ID图像命令创建的状态端口
600231bbd461 mg:httpd apache2ctl -D FOR ... 2分钟前退出(0)2分钟前

docker日志为空

 λDocker事件
2017-09-08T15:26:10.726720800 + 05:30容器创建5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157(image = mg:httpd,name = zealous_ritchie)
2017-09-08T15:26:10.740310700 + 05:30容器附加5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157(image = mg:httpd,name = zealous_ritchie)$ b:b 2017-09-08 :11.035777100 + 05:30网络连接2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143(容器= 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157,name = bridge,$ = b:26:09 + 05:T09:$ 08:b:b:type:-09-05) 30卷装入e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26(容器= 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157,目的地=的/ var /数/ apache2的,驱动器=本地,传播=,读/写=真)
2017-09-08T15:26:11.548736900 + 05:30开始容器5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157(image = mg:httpd,name = zealous_ritchie)
2017-09-08T15:26:11.573272300 + 05:30容器大小调整5325b79abe1988312952629165551c169a8bdc3fbe6177(1783) )
2017-09-08T15:26:12.733164900 + 05:30容器模具5325b79abe1988312952629629165551c169a8bdc3fbe6e473cf0177859db7c0157(exitCode = 0,image = mg:httpd,name = zealous_ritchie)
2017-09-08T15:26:13.227455 05:30网络断开连接2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143(容器= 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157,名称=网桥,类型=网桥)
2017:18:00 3.306885700 + 05:30卸下卷e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26(container = 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db
$ b>原因?未启动容器时如何查看apache log\conf文件?

解决方案

因此,您的Web服务器不是作为前台进程启动的,这就是为什么立即停止容器的原因。



我认为您应该更改

  ENTRYPOINT [ apache2ctl, -D,  FOREGROUND] 

  CMD [ apache2ctl,-D, FOREGROUND] 

因为您要在挂载容器时运行该命令。



ENTRYPOINT 指令声明可执行文件,用于执行 CMD

  ENTRYPOINT [ apache2ctl,  -D, FOREGROUND] 
导致:
$ apache2ctl -D FOREGROUND<来自运行命令行或CMD指令的命令>

来自Ubuntu映像的默认命令我可以找到的是 / bin / bash
因此,当您使用以下命令运行容器时:

  docker run -it mg:httpd 

执行的结果命令将是:

  $ apache2ctl -D FOREGROUND / bin / bash 

显然没有多大意义。我建议浏览

经过上述更改后,它看起来像这样:

 (默认)ENTRYPOINT [ / bin / sh, -c] 
CMD [ apache2ctl, -D, FOREGROUND]
结果如下:
$ / bin / sh -c apache2ctl -D FOREGROUND


I am new to Docker. My Dockerfile (got from a tutorial) is:

FROM ubuntu

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends apache2 \
                        libapache2-mod-jk
VOLUME ["/var/log/apache2"]
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
EXPOSE 80 443

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]

I gave docker build -t mg:httpd apache\. No errors.

λ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                SIZE
mg                  httpd               262d7a4f85fc        About an hour ago      248MB

docker run -it mg:httpd

No errors, but the cursor returns to command prompt immediately. Getting Unable to connect on taking http://localhost/ in browser.

λ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                         PORTS                
600231bbd461        mg:httpd            "apache2ctl -D FOR..."   2 minutes ago       Exited (0) 2 minutes ago             

docker logs is empty

λ docker events
2017-09-08T15:26:10.726720800+05:30 container create 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:10.740310700+05:30 container attach 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:11.035777100+05:30 network connect 2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, name=bridge, type=bridge)
2017-09-08T15:26:11.090873500+05:30 volume mount e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, destination=/var/log/apache2, driver=local, propagation=, read/write=true)
2017-09-08T15:26:11.548736900+05:30 container start 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:11.573272300+05:30 container resize 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (height=41, image=mg:httpd, name=zealous_ritchie, width=168)
2017-09-08T15:26:12.733164900+05:30 container die 5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157 (exitCode=0, image=mg:httpd, name=zealous_ritchie)
2017-09-08T15:26:13.227455500+05:30 network disconnect 2b8829b336575a2aa2210f55105d793e8f1b196d51845d38d3dc8ff322af6143 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, name=bridge, type=bridge)
2017-09-08T15:26:13.306885700+05:30 volume unmount e8421cbd867fca04f0dd3ee6da815c59cad5fc32c5a427710d144213b43caa26 (container=5325b79abe1988312952629165551c169a8bdc3fbe6e473cf0177859db7c0157, driver=local)

what could be the reason? How can I look into the apache log\conf files when the container is not started?

解决方案

So your Webserver is not startet as a foreground process, that is why the container is stopped immediately.

I think you should change

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]

to

CMD ["apache2ctl", "-D", "FOREGROUND"]

Because you want that command to run when the container is mounted.

The ENTRYPOINT directive declares the executable which is used to execute the CMD.

ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]
results in:
$  apache2ctl -D FOREGROUND <command either from the run command line or the CMD directive>

The default command from Ubuntu image I could find is /bin/bash. So when you run the container using:

docker run -it mg:httpd

the resulting command that is executed will be:

$  apache2ctl -D FOREGROUND /bin/bash

what obviously does not make much sense. I would recommend to go over that post, it explains the details very well.

After the change described above it will look like that:

(default) ENTRYPOINT ["/bin/sh", "-c"]
CMD ["apache2ctl", "-D", "FOREGROUND"]
what results in:
$  /bin/sh -c "apache2ctl -D FOREGROUND"

这篇关于为什么httpd容器立即退出而在Docker中没有任何错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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