Before you begin

In this tutorial, we’ll learn how to deploy Moodle using Docker and Docker Compose. In order to do that we only need a GNU Linux machine/server with permission to install software in it. Docker and docker-compose is not required because scripts will be provided in the following steps.

Install Docker Engine

Commands to install Docker on Debian:

USER=$(whoami)

sudo groupadd docker
sudo usermod -aG docker $(whoami)

sudo apt-get update
sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/debian \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce

More information about how to install Docker on different flavours of Linux or on another OS here: https://docs.docker.com/engine/installation/

Install Docker Compose

Commands to install Docker on Ubuntu:

VERSION=1.16.1

curl -L https://github.com/docker/compose/releases/download/$VERSION/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

More information about how to install docker-compose here: https://docs.docker.com/compose/install/

Create and run a docker-compose file

Once we have docker and docker-compose installed we should create the following docker-compose file. For example at $HOME/docker-compose.yml:

version: '3'
volumes:
  mariadb_data:
  moodle_data:
networks:
  moodle:
services:
  mariadb:
    image: 'bitnami/mariadb:latest'
    environment:
      - MARIADB_USER=bn_moodle
      - MARIADB_DATABASE=bitnami_moodle
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - 'mariadb_data:/bitnami'
    networks:
      - moodle
  moodle:
    image: 'bitnami/moodle:latest'
    environment:
      - MARIADB_HOST=mariadb
      - MARIADB_PORT_NUMBER=3306
      - MOODLE_DATABASE_USER=bn_moodle
      - MOODLE_DATABASE_NAME=bitnami_moodle
      - ALLOW_EMPTY_PASSWORD=yes
      - MOODLE_USERNAME=my_admin_user
      - MOODLE_PASSWORD=my_admin_pass
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - 'moodle_data:/bitnami'
    depends_on:
      - mariadb
    networks:
      - moodle

Please change MOODLE_USERNAME=MY_USER and MOODLE_PASSWORD=MY_PASSWORD with your user and password custom values.

mariadb container definition contains ALLOW_EMPTY_PASSWORD and it’s linked on the moodle container. More information about available ENV vars here: https://hub.docker.com/r/bitnami/moodle/

Finally and in the same folder of the $HOME/docker-compose.yml file run:

$ cd $HOME
$ docker-compose up -d

Final checks

  • Check main page is available at: http://[MY_IP_ADDRESS_OR_DOMAIN]
  • Check you can enter to the admin area using http://[MY_USER]:[MY_PASSWORD]@[MY_IP_ADDRESS_OR_DOMAIN]/login/index.php

More info about bintami Moodle Docker image at: https://hub.docker.com/r/bitnami/moodle/