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:
rm moodle/src/.keep
git clone -b MOODLE_501_STABLE https://github.com/moodle/moodle.git moodle/src- 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"Install mkcert and its dependencies:
brew bundleInstall the Docker compose stack:
docker compose -f docker-compose.local.yml buildGenerate the certificates for localhost:
docker compose -f docker-compose.local.yml run --rm mkcertInstall the local certificates:
mkcert -installRun the stack:
docker compose -f docker-compose.local.yml up -d- Remove Moodle's sources volume
docker compose down
docker volume ls
docker volume rm docker-moodle_moodle_src- Rebuild
docker compose build --no-cache- Run the upgrade cli
docker compose exec moodle php admin/cli/upgrade.php
docker compose exec moodle php admin/cli/purge_caches.php