Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache in Docker won't deliver sites

After installing an apache webserver in a docker container, I wanted to display a sample page just to make sure it works. However I always get 404 Not found.

Here's the dockerfile

FROM ubuntu:14.04
MAINTAINER <[email protected]>
RUN DEBIAN_FRONTEND=noninteractive

# Install required packages
RUN apt-get -y update
RUN apt-get install -y apache2 libapache2-mod-php5 php5-gd php5-json php5-mysql php5-curl php5-intl php5-imagick bzip2 wget

# Enable the php mod
RUN a2enmod php5

# Configuration for Apache
ADD ./apache.conf /etc/apache2/sites-available/
RUN ln -s /etc/apache2/sites-available/apache.conf /etc/apache2/sites-enabled/
RUN a2enmod rewrite

RUN mkdir /var/www/test && echo "<html><body><h1>Yo</h1></body></html>" >> /var/www/test/index.html

EXPOSE :80

CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

apache.conf

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www

    <Directory /var/www/test/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

The container is up and running. Port 80 is forwarded to 8080 on the host machine.

When I browse to localhost:8080, I can see the apache2 default page. However, when I go to localhost:8080/test/index.html I do only get 404 Not found.

like image 319
Explicat Avatar asked Sep 30 '22 07:09

Explicat


1 Answers

This is because you still have the default sites-enabled config.

To remove this file, you should add a line to remove this (probally around about the same place as where you add the new vhost configuration) with:

RUN rm -rf /etc/apache2/sites-enabled/000-default.conf
like image 76
Marcus Hughes Avatar answered Oct 19 '22 06:10

Marcus Hughes