Moodle Docker Compose

Single-container Moodle 5.1 with MySQL 8.4 and PHP 8.5, served by Apache on port 8000.

Overview

A single-container Docker setup that runs Moodle 5.1 with MySQL 8.4 and PHP 8.5 on Ubuntu 26.04 (Resolute), served by Apache on port 8000. Everything — Apache, PHP, MySQL, and cron — runs inside one container.

Stack

Component Version
Ubuntu26.04 (Resolute)
Moodle5.1 (MOODLE_501_STABLE)
MySQL8.4
PHP8.5
Web serverApache 2.4

Quick Start

git clone https://github.com/waterloobae/moodle-docker-compose.git
cd moodle-docker-compose
docker compose up --build

First boot takes several minutes — Moodle is cloned from GitHub and the database installer runs automatically. Once you see Starting Apache... in the logs, open http://localhost:8000.

Field Value
Usernameadmin
PasswordAdmin@1234

Common Commands

# Start (after initial build)
docker compose up

# Wipe all data and start clean
docker compose down -v && docker compose up --build

# View live logs (filtered)
docker logs -f moodle_app 2>&1 | grep -E "(Success|failed|Starting Apache|installation complete|ERROR|==>)"

# Open a shell in the container
docker exec -it moodle_app bash

# View Moodle cron log
docker exec moodle_app tail -f /var/log/moodle_cron.log

Architecture

All services run in a single container (moodle_app). On each start, entrypoint.sh runs and is fully idempotent:

  1. Sets up /var/run/mysqld with chmod 755 so www-data can access the socket.
  2. Initialises the MySQL data directory (first run only).
  3. Starts mysqld in the background.
  4. Creates the moodle database and user (first run only).
  5. Runs the Moodle CLI installer (first run only).
  6. Starts cron (runs cron.php every minute as www-data).
  7. Starts Apache in the foreground.

Volumes

Volume Mount point Purpose
mysql_data/var/lib/mysqlMySQL data
moodle_html/var/www/html/moodleMoodle source + config.php
moodle_data/var/moodledataUser files, cache, sessions

Troubleshooting

"Database connection failed"

/var/run/mysqld/ permissions issue. Run docker compose restart.

"Access denied for user root"

Stale volume. Run docker compose down -v && docker compose up --build.

MySQL won't start

docker exec moodle_app cat /var/log/mysql/error.log

Moodle installer skipped but broken

Stale moodle_html volume. Run docker compose down -v && docker compose up --build.