How to run apache2 automatically in Ubuntu docker container?

I am trying to create a Docker file that will automatically launch apache. Nothing worked. But if I write to the container and run service apache2 start , it will work. Why can't I run this command from my Docker file?

 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 service apache2 start 
+13
source share
2 answers

The problem is here: CMD service apache2 start When this command is executed, the apache2 process will be disconnected from the shell. But Docker only works when the main process is alive.

The solution is to run Apache in the foreground . Dockerfile should look like this: (only the last line has 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 
+27
source

For me, the last line with CMD was wrong:

 # it helped me CMD ["apachectl", "-D", "FOREGROUND"] 
0
source

Source: https://habr.com/ru/post/1268564/


All Articles