Upgrade Moodle Docker
I found out that upgrading moodle (running in a Docker container) is not as simple as doing docker pull image
.
It requires some more steps, that are properly referenced in the Moodle’s documentation – version 4.4
Backing up Docker volumes
As always, backup everything before doing any kind of updates.
-
Start by stopping the relevant Docker containers
docker stop moodle mariadb
-
Then, back up the Moodle volume (change according to your setup)
docker run --rm -v ~/moodle-bak:/backups --volumes-from moodle busybox cp -a /bitnami/moodle /backups/latest
A quick commands explanation
- docker run: Launches a new Docker container.
- –rm: Automatically removes the container after completion of the task.
- -v ~/moodle-bak:/backups: Mounts the host directory
~/moodle-bak
into the container at/backups
, allowing file storage on your host. - –volumes-from moodle: Grants the new container access to the volumes of the existing
moodle
container. - busybox: Uses the lightweight BusyBox image, ideal for simple tasks.
- cp -a /bitnami/moodle /backups/latest: Copies the entire
/bitnami/moodle
directory (preserving file attributes) into/backups/latest
on the container, which maps to~/moodle-bak/latest
on your host.
Upgrading Moodle
As per documented, upgrading to the latest moodle version requires the following steps.
-
Backup the existing Moodle folder
Rename or move your current Moodle folder to a backup location (e.g.,moodle-bak
). -
Download and Extract the latest Moodle package
Obtain the latestmoodle.tgz
file from the official Moodle sources and extract it. -
Restore critical files
Copy essential configuration and custom files from your backup into the new Moodle directory:cp moodle-bak/config.php moodle cp -pr moodle.backup/theme/mytheme moodle/theme/mytheme cp -pr moodle.backup/mod/mymod moodle/mod/mymod
-
Set ownership and permissions
Update the file ownership and permissions as recommended:chown -R root:root moodle chmod -R 755 moodle
On Debian Linux, you might consider creating a dedicated user for Moodle rather than using the web server user (e.g.,
www-data
). -
Update Docker configuration
In your newdocker-compose
file, replace the Docker volume with a bind mount that points to your Moodle directory on the host. This creates a persistent volume for the upgraded installation. -
Restart your containers
Finally, start your Docker Compose setup to bring up the upgraded Moodle instance.