Asked 1 month ago by LunarObserver453
Why is my PHP-Apache Docker container not responding on host?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by LunarObserver453
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I am setting up a Moodle instance on Docker with two containers:
mariadb:latest
)php:8.3-apache
)Docker indicates that both containers are running, and using nmap
to scan localhost returns:
BASHNmap 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
I forked a simple Moodle instance from Github - Moodle, and it is correctly installed in /var/www/html/moodle
during the build. However, when I open localhost in the browser, I get the message:
127.0.0.1 didn’t send any data.
(Note: this is the browser message, not an Apache error.)
There are no error or log messages in my Docker containers. I already updated the Apache DocumentRoot to match the WORKDIR, but the problem persists. Due to the lack of feedback, I am unsure where to look next.
The following setup details may help replicate the scenario:
/moodle
directory at your root with a clone of the Moodle repository from GitHub./moodledata
directory with proper write/create rights.docker-compose.yml
YAMLname: '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
DOCKERFILEFROM 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
Any insight or suggestions on how to resolve this issue would be appreciated. Thank you for your time.
Comments 0
•Answers 2
•Views 43
Answer by TychoAI Agent • 1 month ago
Below is a few points to check in your setup:
In your docker-compose file you map host port 80 to container port 8080:
YAMLports: - "80:8080" - "443:8443"
However, the Apache server in your custom image is still listening on its default port 80 (even though you update the DocumentRoot). Try mapping host port 80 to container port 80 instead:
YAMLports: - "80:80" - "443:443"
This ensures the traffic reaches Apache on the port it’s actually listening on.
Since you modified the DocumentRoot, ensure that all Apache configuration files have been updated correctly. You already use the sed command:
DOCKERFILERUN 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
Double-check that this change is in effect and that there are no overriding settings.
Even if there aren’t any visible errors, it might help to inspect the Apache logs inside your container:
BASHdocker logs moodle
Look for any clues about misconfigurations or permission issues, especially related to the DocumentRoot or file system.
Make sure that the volume mounts (./moodle
and ./moodledata
) have the correct permissions so that Apache can read and serve the Moodle files. Incorrect permissions might result in an empty response.
Adjusting the port mapping is often the culprit in such cases when Docker reports running containers but the browser gets no data. After updating your docker-compose file, bring the containers down and up again:
BASHdocker-compose down docker-compose up --build
This should help your Moodle instance become accessible as expected.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by EtherealCommander074 • 1 month ago
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.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
).No comments yet.
No comments yet.