Search code examples
phpdockerapachedocker-composemoodle

Apache is running on Docker but is not receiving a response on host


Trying to run a Moodle instance on Docker using php-apache

Hi, I am currently trying to set up a moodle instance using Docker.

  • A mariadb container (image: mariadb:latest)
  • A php container (image: php:8.3-apache)

According to docker everything is running and if I use nmap to ping the adress, I get:

Nmap scan report for localhost (127.0.0.1)
Host is up (0.000099s latency).
Not shown: 997 closed tcp ports (conn-refused)
PORT     STATE SERVICE
80/tcp   open  http
443/tcp  open  https
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds

My code is a simple fork from Github - Moodle and has correctly been installed in /var/www/html/moodle on build.

Error: Empty response

When I open my localhost in the browser, I get 127.0.0.1 didn’t send any data. (note: this is a browser message, not an apache error message). I am not getting any error/log messages in my docker containers..

I updated the apache DocumentRoot to match the WORKDIR, but the problem still persists. Due to the lack of error/feedback I am finding it difficult to figure out where to look.

Setup Docker

Here are my docker files in case you want to replicate my scenario:

  • create a /moodle directory in your root containing a clone from this Github repository
  • create a /moodledata repository that is empty (make sure it has write/create rights)

docker-compose.yml

name: 'moodle_405'

services:
  mariadb:
    image: mariadb:latest
    container_name: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=bitnami
      - MYSQL_DATABASE=moodle
      - MYSQL_USER=admin
      - MYSQL_PASSWORD=password
    volumes:
      - ./mariadb:/var/lib/mysql
    ports:
      - "3306:3306"

  moodle:
    image: php:8.3-apache
    container_name: moodle
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_NAME=moodle
      - MOODLE_DATABASE_USER=admin
      - MOODLE_DATABASE_PASSWORD=password
    volumes:
      # ./moodle contains a simple fork from moodle's github repository
      - ./moodle:/var/www/html/moodle
      # ./moodledata is an empty folder that will be updated during moodle's setup
      - ./moodledata:/var/www/moodledata
    depends_on:
      - mariadb
    ports:
      - "80:8080"
      - "443:8443"

Dockerfile

FROM php:8.3-apache

LABEL maintainer="John Whick <[email protected]>"
LABEL description="John's Moodle setup for docker"
LABEL version="1.2"

# PHP extensions
RUN apt-get update && apt-get install -y \
    libpng-dev \
    libjpeg-dev \
    libfreetype6-dev \
    libxml2-dev \
    libzip-dev \
    unzip \
    git \
    && docker-php-ext-install mysqli zip gd xml soap intl \
    && a2enmod rewrite

# Set Apache DocumentRoot
RUN sed -ri -e 's!/var/www/html!/var/www/html/moodle!g' \
    /etc/apache2/sites-available/*.conf \
    /etc/apache2/apache2.conf \
    /etc/apache2/conf-available/*.conf

WORKDIR /var/www/html/moodle

EXPOSE 80
EXPOSE 8080

Thank you for your time.


Solution

  • Due to the lack of error/feedback I am finding it difficult to figure out where to look.

    Between nmap and the browser there is a lot of room, if it helps to smallen the gaps:

    • curl -iv http://127.0.0.1:80/ from your shell. If the browser returned "no-data", curl will tell you more about the connection information. IIRC nmap only checks something is listening on the port ("the port is open"), curl will actually try to talk HTTP there.
    • The Apache HTTP Server has decent logging settings including up to debug. And it has different logs. You would like to find out if there are any diagnostics in the server logs including startup messages.
    • Then there is the access log you can make use of to validate if the request send by curl is actually hitting the server. Follow the logs while entering the machine.
    • I'm not totally fluent with the PHP container in the Apache variant, but you may need to find out first where the logs are and what their level is. As long as a specific log is not streamed to the containers STDOUT or STDERR (standard streams), you will not be able to see them with docker log <container> but instead you have to follow the file itself (use the docker exec function to enter the container, the PHP images have bash and are debian based: docker exec -it <container> /bin/bash).