How to start apache2 automatically in a ubuntu docker container?
For me last line with CMD was wrong:
# it helped me
CMD ["apachectl", "-D", "FOREGROUND"]
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 / 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