Reputation: 39
So I built a Docker image of a Laravel project I'm working on, but when I run the containers (with docker-compose up), I can't access the application.
I'm currently using Docker Toolbox for Windows, so I use the IP from the docker-machine, but all I get is "The requested URL / was not found on this server." (404).
In the Docker Terminal, I get the following warnings:
php-apache_1 | AH00112: Warning: DocumentRoot [/var/www/html] does not exist
php-apache_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
php-apache_1 | [Fri Mar 15 14:04:10.964296 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
I navigated through the directories inside the container (with docker exec -it) and, indeed, the /var/www/html directory doesn't exist, once the /var/www directory is empty, but it shouldn't be!!
In the php-apache.dockerfile I copied all my project to the /var/www directory, so it shouldn't be empty.
I've been trying to solve this for a while now, so if anyone could help me I would really appreciate it.
Here is the php-apache.dockerfile:
FROM php:7.2.9-apache-stretch
RUN apt-get update && apt-get install -y libxml2-dev && apt-get install -y
libcurl3-dev
RUN docker-php-ext-install pdo_mysql mbstring tokenizer xml ctype json
RUN mkdir storage &&\
mkdir storage/logs &&\
mkdir storage/app &&\
mkdir storage/framework &&\
mkdir storage/framework/cache &&\
mkdir storage/framework/sessions &&\
mkdir storage/framework/views &&\
mkdir -p bootstrap/cache
COPY composer.json composer.lock /var/www/
WORKDIR /var/www
COPY . /var/www
RUN curl --silent https://getcomposer.org/installer | php &&\
composer install
COPY public /var/www/html
RUN chown -R www-data:www-data \
/var/www/storage \
/var/www/bootstrap/cache
RUN a2enmod rewrite
EXPOSE 80
And the docker-compose.yml:
version: '3'
services:
db:
image: mysql:latest
environment:
- MYSQL_USER=root
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=ontologyFramework
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
ports:
- "3306:3306"
php-apache:
depends_on:
- db
build:
dockerfile: phpapache.dockerfile
context: .
volumes:
- ./:/var/www
ports:
- "80:80"
environment:
- DB_PORT=3306
- DB_HOST=127.0.0.1
links:
- db
Upvotes: 3
Views: 2278
Reputation: 1357
It looks like the problem is with your docker-compose.yml
file. The files you are copying to /var/www
in your php-apache.dockerfile
are being hidden by the volume mapping in your docker-compose.yml
file. Remove the following lines from the compose file:
volumes:
- ./:/var/www
Upvotes: 1