Install Moodle Inside Docker Container in Linux

Install Moodle Inside Docker Container in Linux

Moodle is a learning management platform that designed for educators and learners. Moodle is an open-source project available under the GPLv3+ license.

This tutorial explains how to install Moodle inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

You also need to have a running MySQL container. Instructions can be found in the post.

Install Moodle

Before starting, create moodle database:

docker exec -it mysql mysql -u root -p -e "CREATE DATABASE moodle"
  • Host network

Run the following command to create a container for Moodle that uses host network:

docker run -d --name=moodle --restart=always --network=host \
    -v /opt/moodle/data:/bitnami \
    -e MOODLE_USERNAME=admin \
    -e MOODLE_PASSWORD=pwd123 \
    -e MOODLE_DATABASE_TYPE=mysqli \
    -e MOODLE_DATABASE_USER=root \
    -e MOODLE_DATABASE_PASSWORD=pwd123 \
    -e MOODLE_DATABASE_NAME=moodle \
    -e MOODLE_DATABASE_HOST=127.0.0.1 \
    bitnami/moodle

MySQL container should run on host network as well.

  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, Moodle service is listening on port 8080. It can be changed with -p option.

docker network create app-net
docker run -d --name=moodle --restart=always --network=app-net \
    -p 8081:8080 \
    -v /opt/moodle/data:/bitnami \
    -e MOODLE_USERNAME=admin \
    -e MOODLE_PASSWORD=pwd123 \
    -e MOODLE_DATABASE_TYPE=mysqli \
    -e MOODLE_DATABASE_USER=root \
    -e MOODLE_DATABASE_PASSWORD=pwd123 \
    -e MOODLE_DATABASE_NAME=moodle \
    -e MOODLE_DATABASE_HOST=mysql \
    bitnami/moodle

MySQL container should run on the same user-defined bridge network as well.

Notes:

  • It might take a while before initialization is finished and the Docker container starts to respond to requests.
  • Don't forget to change admin password for Moodle using MOODLE_PASSWORD.
  • The MOODLE_DATABASE_USER and MOODLE_DATABASE_PASSWORD can be used to specify MySQL credentials.
  • When user-defined bridge network is used, don't forget to change MOODLE_DATABASE_HOST. It specifies MySQL container name.

Testing Moodle

Open a web browser and go to http://<IP_ADDRESS>:8080, where <IP_ADDRESS> is the IP address of the system. Log in to the dashboard with the admin username and password.

Moodle Inside Docker Container in Linux

Uninstall Moodle

To completely remove Moodle, remove its container:

docker rm --force moodle

Remove Moodle image:

docker rmi bitnami/moodle

You can also remove Moodle data:

sudo rm -rf /opt/moodle

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.