A Docker Compose stack for deploying Moodle with a Traefik proxy.
moodle- The Moodle PHP-FPM application containermoodle-web- Nginx container exposing Moodle to Traefikdb- MariaDB container for Moodle's databaseredis- Redis container for caching and session storagetraefik- Traefik reverse proxy handling routing and HTTPS
| Volume | Purpose |
|---|---|
moodle_src |
The Moodle application source code. Mounted inside the Moodle container at /var/www/html. |
moodle_data |
The moodledata (cache, sessions, files, uploaded content). Mounted at /var/moodledata in the Moodle container. |
db_data |
The MariaDB database persistence. |
redis_data |
Redis data persistence (if configured) for caching and session storage. |
Download and place the Moodle source files in the moodle/src folder.
You should have a structure like: moodle/src/[ Moodle sources files].
-
Copy the sample file .env-sample as
.envand fill in the missing information. -
Create the network:
docker network create web- Prepare the Docker stack:
- Edit your
.envfile - Configure the
traefik/acme.jsonfile with the right permissions:
chmod 600 traefik/acme.json
chown $USER:$USER traefik/acme.json- Download and prepare Moodle sources:
wget -P moodle/src https://download.moodle.org/download.php/direct/stable501/moodle-latest-501.tgz
tar -xf moodle/src/moodle-latest-501.tgz -C moodle/src
mv moodle/src/moodle/{*,.*} moodle/src/ 2>/dev/null && \
rmdir moodle/src/moodle 2>/dev/null && \
rm moodle/src/moodle-latest-*.tgz- Build the stack:
docker compose up --build- Launch the app:
docker compose up -dUncomment the following lines in docker-compose.yml to let Traefik display debug logs:
- "--log.level=DEBUG"
- "--accesslog=true"
- "--accesslog.format=json"Log into the MariaDB container:
docker compose exec db mariadb -u moodle -p moodleReal time stats:
docker statsObserve dockerd processes:
ps aux | grep dockerd | grep -v grepMemory use by dockerd daemon:
ps aux | grep dockerd | awk '{print $4, $11}' | sort -nr
ps aux --sort=-%mem | head -20App & Traefik logs:
docker compose logs -f moodle
docker logs traefikdocker volume ls
docker run --rm -v docker-moodle_db_data:/volume -v /opt/backup:/backup alpine tar czvf /backup/backup_moodle_db_data.tar.gz -C /volume .Remove the containers:
docker compose downDelete the volumes:
docker volume rm docker-moodle_db_dataCreate the volumes:
docker volume create docker-moodle_db_dataRestore the backups:
docker run --rm -v docker-moodle_db_data:/volume -v /opt/backup:/backup alpine sh -c "tar xzvf /backup/backup_moodle_db_data.tar.gz -C /volume"