Explicat
Explicat

Reputation: 1095

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.

Upvotes: 8

Views: 15812

Answers (3)

Mike J
Mike J

Reputation: 425

I just had a similar issue like this, and was able to resolve it.

First determine that apache2 is running or not

/etc/init.d/apache2 status

If it is not running, you can add this to your dockerfile:

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

Upvotes: 0

Kryten
Kryten

Reputation: 15760

My guess is that it's a permissions issue. Remember, when creating the docker container from the dockerfile, everything is run as root. So your /var/www/test/index.html file is owned by root. My guess is that it has some restricted permissions.

Try this:

After

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

add

RUN chmod 0755 /var/www/test/index.html

This will reset the permissions on that file so that anyone can read it. If I'm right, that will fix your problem.

Upvotes: 0

Marcus Hughes
Marcus Hughes

Reputation: 5503

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

Upvotes: 5

Related Questions