Before you begin

In this tutorial will learn how to deploy Moodle on a remote/local server/machine using Docker and docker-compose. In order to do that we only need a 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: '2'
services:
  mariadb:
    image: 'bitnami/mariadb:latest'
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - '/var/opt/moodle/mariadb_data:/bitnami'
  moodle:
    image: 'bitnami/moodle:latest'
    environment:
      - MOODLE_USERNAME=MY_USER
      - MOODLE_PASSWORD=MY_PASSWORD
    labels:
      kompose.service.type: nodeport
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - '/var/opt/moodle/moodle_data:/bitnami'
    depends_on:
      - mariadb
volumes:
  mariadb_data:
    driver: local
  moodle_data:
    driver: local

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/