且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 ubuntu docker 容器中自动启动 apache2?

更新时间:2022-03-28 22:49:46

问题出在这里:CMD service apache2 start 当你执行这个命令时,进程 apache2 将被分离从外壳.但是 Docker 仅在主进程处于活动状态时工作.

The issue is here: CMD service apache2 start When you execute this command process apache2 will be detached from the shell. But Docker works only while main process is alive.

解决方案是在前台中运行 Apache.Dockerfile 必须如下所示:(只更改了最后一行).

The solution is to run Apache in the foreground. Dockerfile must look like this: (only last line changed).

FROM ubuntu

# File Author / Maintainer
MAINTAINER rmuktader

# Update the repository sources list
RUN apt-get update

# Install and run apache
RUN apt-get install -y apache2 && apt-get clean

#ENTRYPOINT ["/usr/sbin/apache2", "-k", "start"]


#ENV APACHE_RUN_USER www-data
#ENV APACHE_RUN_GROUP www-data
#ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80
CMD apachectl -D FOREGROUND