Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Deploy Moodle With Docker

Minimum Hardware Recommendations

  • 1 vCPU
  • 2GB Memory

Steps

Install Docker

Install Docker and Docker compose if you haven't already.

Download Images

Run the following commands to download the docker images we will be using later. Whilst that is downloading, open another shell and proceed with this tutorial.

docker pull mariadb:10
docker pull bitnami/moodle:3

Docker Compose File

Copy the following code and put into a docker-compose.yml file on your server. **Be sure to change the MYSQL_PASSWORD and MOODLE_DATABASE_PASSWORD variables (which need to match each other).

version: '2'
services:
  mariadb:
    image: 'mariadb:10'
    container_name: db
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: moodle
      MYSQL_USER: moodle
      MYSQL_PASSWORD: moodlePassword
    volumes:
      - $HOME/volumes/mysql:/var/lib/mysql

  moodle:
    image: 'bitnami/moodle:3'
    container_name: moodle
    environment:
      MOODLE_USERNAME: programster
      MOODLE_PASSWORD: thisIsMyMoodleLoginPassword
      MOODLE_EMAIL: admin@programster.org
      MARIADB_HOST: db
      MARIADB_PORT_NUMBER: 3306
      MOODLE_DATABASE_USER: moodle
      MOODLE_DATABASE_NAME: moodle
      MOODLE_DATABASE_PASSWORD: moodlePassword
      ALLOW_EMPTY_PASSWORD: "no"
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - $HOME/volumes/moodle:/bitnami'
    depends_on:
      - mariadb

volumes:
  mariadb_data:
    driver: local
  moodle_data:
    driver: local

Run the following command to start your containers.

docker-compose up

Watch it for a while and eventually you will see:

db         | 2020-03-21 20:03:10 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: '172.20.0.3' (This connection closed normally without authentication)
moodle     | mysql-c INFO  Found MySQL server listening at db:3306
moodle     | mysql-c INFO  MySQL server listening and working at db:3306
moodle     | moodle  INFO  Running Moodle install. Please be patient...

Just keep waiting, preferably watching htop/top for when the CPU calms down.

Log In

When your CPU does calm down, navigate to your server's hostname or IP in your browser and you will see your moodle site.

Click the login links and enter the values for the MOODLE_USERNAME and MOODLE_PASSWthisIsMyMoodleLoginPasswordORD that you set earlier in your docker-compose file.

You should now be logged in as an admin and can manage the rest through the web UI.

References

Last updated: 21st March 2020
First published: 21st March 2020

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch