Skip to Content

Installing Moodle on Docker

Moodle is a popular open-source learning management system (LMS) used by educational institutions worldwide. Docker provides a convenient way to deploy Moodle, offering a quick and reliable environment for running the application. In this guide, we'll show you how to install Moodle on Docker using pre-made images from Docker Hub.

Step 1: Pull the Moodle Docker Image from Docker Hub

The easiest way to get started with Moodle on Docker is by using a pre-made image from Docker Hub. These images are maintained by the official Moodle team, ensuring that they’re up-to-date and secure.

To pull the official Moodle image, run the following command in your terminal:

docker pull moodle/moodle


This will download the latest Moodle image from Docker Hub to your local machine.

Step 2: Create a docker-compose.yml File


To set up Moodle with Docker, we’ll use Docker Compose to define and run multi-container applications. This file will specify all the services required to run Moodle, such as the database and Moodle itself.


Create a docker-compose.yml file in your project directory with the following content:

version: '3.7'


services:

  moodle:

    image: moodle/moodle

    ports:

      - "8080:80"

    environment:

      MOODLE_DB_HOST: db

      MOODLE_DB_NAME: moodle

      MOODLE_DB_USER: moodleuser

      MOODLE_DB_PASSWORD: moodlepassword

    depends_on:

      - db

    networks:

      - moodle_net

    volumes:

      - moodledata:/var/www/html


  db:

    image: mysql:5.7

    environment:

      MYSQL_ROOT_PASSWORD: rootpassword

      MYSQL_DATABASE: moodle

      MYSQL_USER: moodleuser

      MYSQL_PASSWORD: moodlepassword

    networks:

      - moodle_net

    volumes:

      - dbdata:/var/lib/mysql


networks:

  moodle_net:

    driver: bridge


volumes:

  moodledata:

  dbdata:


Step 3: Explanation of the docker-compose.yml File

Here’s a breakdown of the docker-compose.yml file:

  • Moodle Service: This service runs the Moodle application. It uses the official Moodle image (moodle/moodle), exposes port 8080 on your local machine (so you can access it at http://localhost:8080), and sets the necessary environment variables for database connectivity (like MOODLE_DB_HOST, MOODLE_DB_NAME, MOODLE_DB_USER, and MOODLE_DB_PASSWORD).
  • Database (MySQL) Service: The db service uses the official MySQL image (mysql:5.7) to run a MySQL database for Moodle. It also sets the database root password and creates a specific user for Moodle with a password. This service depends on the db container and connects to it through the moodle_net network.
  • Networks: Both the moodle and db services are connected via a custom bridge network (moodle_net) to enable communication between them.
  • Volumes: Persistent volumes (moodledata and dbdata) are used to store Moodle files and the MySQL database. These volumes are important because they ensure your data is not lost when the containers are stopped or removed.

Step 4: Start the Containers

With your docker-compose.yml file in place, navigate to your project directory in the terminal and run the following command to start the containers:

docker-compose up -d


This command will pull the necessary Docker images (if you haven’t already done so) and start the containers in the background. The -d flag ensures the containers run in detached mode.

Step 5: Access Moodle

Once the containers are up and running, open your web browser and go to:

http://localhost:8080

Step 7: Customize and Manage Moodle

Once Moodle is installed, you can customize it further by modifying the configuration files or installing additional plugins. The Moodle data is stored in the persistent volume, so any changes will be retained even if you restart the container.

How to Install Docker on Ubuntu