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.

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:

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 <babayaga@continental.com>"
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: