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 |
|---|---|
| Ubuntu | 26.04 (Resolute) |
| Moodle | 5.1 (MOODLE_501_STABLE) |
| MySQL | 8.4 |
| PHP | 8.5 |
| Web server | Apache 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 |
|---|---|
| Username | admin |
| Password | Admin@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:
- Sets up
/var/run/mysqldwithchmod 755sowww-datacan access the socket. - Initialises the MySQL data directory (first run only).
- Starts
mysqldin the background. - Creates the
moodledatabase and user (first run only). - Runs the Moodle CLI installer (first run only).
- Starts cron (runs
cron.phpevery minute aswww-data). - Starts Apache in the foreground.
Volumes
| Volume | Mount point | Purpose |
|---|---|---|
mysql_data | /var/lib/mysql | MySQL data |
moodle_html | /var/www/html/moodle | Moodle source + config.php |
moodle_data | /var/moodledata | User 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.