Kubernetes & Docker Linux Ubuntu, Mint & Debian Linux

Moodle in Docker with options for Kubernetes

This article discusses and demonstrates the design and implementation of Moodle using Docker with the option for later deployments with Kubernetes. We’re using Ubuntu 24.04 but this should work fine on similar versions of Ubuntu as well.

The key points are:

  1. Moodle is deployed via a Docker container.
  2. Moodle references an external MariaDB server.
  3. Moodle data is shared across containers.

The diagram below illustrates the above.

With the above scheme, a future deployment using Kubernetes is possible. For this article, we’re going to keep it one step simpler by using local storage on the underling Ubuntu server, and the MariaDB server is also hosted on the underling Ubuntu server.

Install the required software:

apt install mariadb-server docker docker.io docker-compose
Note: In this example, the version of MariaDB is as follows. It’s important to consider the version to be sure Moodle works as expected:
mariadb-server = 1:10.11.8-0ubuntu0.24.04.1
Still with MariaDB installation, set the service to listen on all interfaces:
vi /etc/mysql/mariadb.conf.d/50-server.cnf
 bind-address            = 0.0.0.0
Enable and start MariaDB:
systemctl enable mariadb
systemctl restart  mariadb

Create the new database, create a new user and set a password:

CREATE DATABASE moodle;
CREATE USER 'moodleuser'@'%';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'%';
SET PASSWORD FOR 'moodleuser'@'%' = PASSWORD('sfd34yu3g4geh');
FLUSH PRIVILEGES;

Create a few directories on the Moodle docker server:

mkdir -p /root/moodle-docker/moodle
mkdir -p /root/moodle-docker/moodledata

Create the “docker-compose.yml” file and populate it:

/root/moodle-docker/docker-compose.yml

Add the following content:

services:
  moodle:
    image: docker.io/bitnami/moodle:4.5
  ports:
    - '80:8080'
    - '443:8443'
  environment:
    - MOODLE_DATABASE_HOST=10.1.2.3
    - MOODLE_DATABASE_PORT_NUMBER=3306
    - MOODLE_DATABASE_USER=moodleuser
    - MOODLE_DATABASE_NAME=moodle
    - MOODLE_DATABASE_PASSWORD=sfd34yu3g4geh
    - ALLOW_EMPTY_PASSWORD=no
    - MOODLE_USERNAME=admin
    - MOODLE_PASSWORD=MyPass1
    - BITNAMI_DEBUG=true
  volumes:
    - 'moodle_data:/root/moodle-docker/moodle'
    - 'moodledata_data:/root/moodle-docker/moodledata'
  volumes:
    moodle_data:
      driver: local
    moodledata_data:
      driver: local

Start the docker container:

cd /root/moodle-docker/
docker-compose up -d
You should now be able to visit the new Moodle instance at:
  1. https://<ip-address>/
  2. http://<ip-address>/
The Moodle credentials would be (based on the docker-compose.yml file):
  1. Username: admin
  2. Password: MyPass1

Leave a Reply

Your email address will not be published. Required fields are marked *