无法在docker container

时间:2018-05-30 18:03:25

标签: docker apache2

我的Dockerfile:

FROM ubuntu:latest

RUN apt-get update
RUN apt-get install -y apache2
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf

CMD ["/usr/sbin/apache2ctl","start"]

但是当我构建映像并运行容器时,我会检查apache状态并获取:

root@79074bf56be4:/# service apache2 status
 * apache2 is not running

如果我在容器内手动启动它,它可以工作:

root@79074bf56be4:/# /usr/sbin/apache2ctl start
root@79074bf56be4:/#
root@79074bf56be4:/# service apache2 status
 * apache2 is running
root@79074bf56be4:/# 

我做错了什么?如何让apache2在容器启动时自动启动?

1 个答案:

答案 0 :(得分:0)

对不起,我没有谷歌好看

Here is the same question

通过将CMD线替换为:

来解决
CMD apache2ctl -D FOREGROUND

cuntainer运行命令:

docker run --detach my_image