Docker环境下基于php8.5.3-apache镜像部署Moodle无法通过localhost:8080访问的问题求助
Docker环境下基于php8.5.3-apache镜像部署Moodle无法通过localhost:8080访问的问题求助
大家好,我最近在Docker里用php8.5.3-apache镜像部署Moodle时遇到了访问问题,折腾了好久都没搞定,想请大家帮忙看看!
首先贴一下我的Dockerfile:
FROM php:8.5.3-apache WORKDIR /var/www/html/ # 原本计划复制moodle.conf配置Apache,后来改用了下面的两个配置文件 COPY ./moodle_listener.conf /etc/apache2/moodle_listener.conf COPY ./moodle_listeners.conf /etc/apache2/sites-available/moodle_listeners.conf # 安装依赖 RUN apt-get update && \ apt-get install -y --no-install-recommends \ git \ unzip \ libzip-dev \ libjpeg-dev \ libpng-dev \ libfreetype6-dev \ libpq-dev \ libicu-dev \ libxml2-dev \ libonig-dev && \ docker-php-ext-configure gd --with-freetype --with-jpeg && \ docker-php-ext-install -j$(nproc) zip gd pgsql pdo_pgsql intl soap # 克隆Moodle 5.1稳定版并配置权限 RUN mkdir /var/www/html/moodle && \ cd /var/www/html/moodle && \ git clone -b MOODLE_501_STABLE git://git.moodle.org/moodle.git . && \ chown -R root /var/www/html/moodle/ && \ chmod -R 0755 /var/www/html/moodle/ # 创建Moodle数据目录并设置权限 RUN mkdir -p /var/www/html/moodledata && \ chown -R www-data:www-data /var/www/html/moodledata && \ chmod -R 0777 /var/www/html/moodledata # 启用自定义站点配置 RUN ln -sf /etc/apache2/sites-available/moodle_listeners.conf /etc/apache2/sites-enabled/ CMD ["apache2ctl", "-D", "FOREGROUND"] EXPOSE 8080
这是我的moodle_listeners.conf配置文件:
<VirtualHost *:8080> Include /etc/apache2/moodle_listener.conf </VirtualHost>
另外moodle_listener.conf是参考Moodle代码重构的官方文档来配置的。
我执行了docker run -p 8080:8080 --name moodle_setup moodle5.1命令启动容器后,日志里出现了这些信息:
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message [Tue Mar 03 14:21:37.735910 2026] [mpm_prefork:notice] [pid 8:tid 8] AH00163: Apache/2.4.66 (Debian) PHP/8.5.3 configured -- resuming normal operations [Tue Mar 03 14:21:37.735943 2026] [core:notice] [pid 8:tid 8] AH00094: Command line: '/usr/sbin/apache2 -D FOREGROUND'
我在网上搜了不少方法试,但都没解决问题,希望能得到大家的建议!
03/03/2026 18:32 CET+1 更新
后来我参考了一些建议,做了以下调整:
- 将所有端口映射改为80端口
- 用
COPY ./moodle_listeners.conf /etc/apache2/sites-available/000-default.conf覆盖了Apache默认的000-default.conf(不过我还是想后续调整回更规范的配置方式,保持代码整洁) - 将Apache的DocumentRoot指向
/var/www/html/moodle/public而不是原来的/var/www/html/moodle
现在已经可以正常访问了!谢谢大家的帮助!
备注:内容来源于stack exchange,提问作者Sam
相关产品推荐
相关产品推荐

