2

I am trying to update my .htaccess file on a Docker container. After updating the file, I need to restart Apache. Whenever I try to restart Apache using the command service apache2 restart, I get the following error:

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs Action 'start' failed. The Apache error log may have more information. ...fail!

When I got to the error log, there are no new errors. This is what my Dockerfile looks like:

FROM ubuntu:12.04

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y git curl apache2 php5 libapache2-mod-php5 php5-mcrypt php5-mysql php5-curl vim

# Install app
RUN rm -rf /var/www/*
ADD src /var/www

# Configure apache
RUN a2enmod rewrite
RUN chown -R www-data:www-data /var/www
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

EXPOSE 80

CMD ["/usr/sbin/apache2", "-D",  "FOREGROUND"]
1

TLDR; command to restart apache in your case is kill -USR1 1

Few things needs to be cleared here:

  1. Your docker image is running apache directly using CMD.
  2. this means apache main process will always have PID=1, and you are not using init system.
  3. You are trying to restart apache by using service command which relies on init system. Doh
  4. Alternative way of gracefully restarting apache is to send signal to main process. Read more here: https://httpd.apache.org/docs/current/stopping.html
0

According to your Dockerfile you include your HTML files when when creating your docker image:

ADD src /var/www

So could you explain why you need to edit an .htaccess file after running your image? If you need a different .htaccess file on different hosts, the "docker" way would be to use a data volume when running your container:

docker run -v /path/to/host.htaccess:/var/www/.htaccess user/image

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.