Apache in Docker won't deliver sites

10,520

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
Share:
10,520
Explicat
Author by

Explicat

Updated on September 19, 2022

Comments

  • Explicat
    Explicat over 1 year

    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.

  • Explicat
    Explicat almost 10 years
    Thanks, but I've tried that already. Marcus Hughes answer did the trick.
  • Gajotres
    Gajotres about 7 years
    This is the right answer. I don't know why is default conf file causing these problems but everything works fine after it is disabled or removed. If you don't want to remove it just disable it with: RUN a2dissite 000-default.conf