How to start apache2 automatically in a ubuntu docker container? How to start apache2 automatically in a ubuntu docker container? apache apache

How to start apache2 automatically in a ubuntu docker container?


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.

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

FROM ubuntu# File Author / MaintainerMAINTAINER rmuktader# Update the repository sources listRUN apt-get update# Install and run apacheRUN 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/apache2EXPOSE 80CMD apachectl -D FOREGROUND


For me last line with CMD was wrong:

# it helped meCMD ["apachectl", "-D", "FOREGROUND"]


My project was slightly different where I installed a bunch of other stuff, but the apache start portion matched above. Once I built this image and used it, my server started fine.

FROM ubuntu:latest#install all the tools you might want to use in your containerRUN apt-get updateRUN apt-get install curl -yRUN apt-get install vim -y#the following ARG turns off the questions normally asked for location and timezone for ApacheARG DEBIAN_FRONTEND=noninteractiveRUN apt-get install apache2 -y#change working directory to root of apache webhostWORKDIR var/www/html#copy your files, if you want to copy all use COPY . .COPY index.html index.html#now start the serverCMD ["apachectl", "-D", "FOREGROUND"]