Back to articles
Security & Anti-DDoS

Guide to Self-Hosting Moodle on High-Security Docker Container Clusters for Enterprises

This guide provides a detailed walkthrough for self-hosting Moodle on a Docker container cluster with high security, tailored for enterprises requiring full control over learning...

DPTCloud Engineering4 min read
Guide to Self-Hosting Moodle on High-Security Docker Container Clusters for Enterprises

Image credit: Peter_Lindenau · Pixabay Content License

This guide provides a detailed walkthrough for self-hosting Moodle on a Docker container cluster with high security, tailored for enterprises requiring full control over learning content, user data, and training processes. It covers network configuration, storage, API protection, and secure access using tools like Cloudflare Access, Caddy, and Let's Encrypt on a DDoS-protected VPS infrastructure at DPTCloud.

Introduction

Self-hosting Moodle on a Docker container cluster with high security is an ideal solution for enterprises seeking complete control over learning content, user data, and training workflows. This guide offers a comprehensive deployment of Moodle on Docker with robust security measures, including API authentication, access control, and secure network configuration on DPTCloud’s anti-DDoS VPS platform.

Requirements and Preparation

To deploy Moodle on Docker containers, you need:

  • A VPS server (Cloud VPS Anti-DDoS Anycast L3/L4/L7 at DPTCloud)
  • Ensure the VPS has at least 4GB RAM and 2 CPU cores
  • Assign a primary domain name for Moodle (e.g., moodle.yourcompany.com)
  • Register the domain and configure DNS with an A or CNAME record pointing to the VPS IP
  • Access the VPS via SSH with root privileges

Deploying Moodle on Docker Containers

Follow these steps to deploy Moodle on Docker:

1. Install Docker and Docker Compose

On the VPS, install Docker and Docker Compose:

# Update the system
sudo apt update && sudo apt upgrade -y

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

2. Create docker-compose.yml File

Create a docker-compose.yml file with Moodle, MariaDB, and Nginx configuration:

version: '3.8'

services:
  moodle:
    image: moodle/moodle:latest
    container_name: moodle
    ports:
      - "80:80"
      - "443:443"
    environment:
      - MYSQL_HOST=mariadb
      - MYSQL_USER=moodleuser
      - MYSQL_PASSWORD=moodlepass
      - MYSQL_DATABASE=moodledb
      - MOODLE_HOST=moodle.yourcompany.com
    volumes:
      - ./moodledata:/var/moodledata
    depends_on:
      - mariadb
    restart: unless-stopped

  mariadb:
    image: mariadb:10.6
    container_name: mariadb
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: moodledb
      MYSQL_USER: moodleuser
      MYSQL_PASSWORD: moodlepass
    volumes:
      - ./mariadb_data:/var/lib/mysql
    restart: unless-stopped

  nginx:
    image: nginx:alpine
    container_name: nginx
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
      - ./certs:/certs
    depends_on:
      - moodle
    restart: unless-stopped

3. Configure Nginx and Let's Encrypt

Create an nginx.conf file to configure Nginx and integrate Let's Encrypt:

server {
    listen 80;
    server_name moodle.yourcompany.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name moodle.yourcompany.com;

    ssl_certificate /certs/fullchain.pem;
    ssl_certificate_key /certs/privkey.pem;

    location / {
        proxy_pass http://moodle:80;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Install Let's Encrypt to obtain a free SSL certificate:

# Install Certbot
sudo apt install certbot -y

# Obtain SSL certificate
sudo certbot certonly --nginx -d moodle.yourcompany.com

High Security for Enterprises

To ensure high security, implement the following measures:

1. API Authentication with Cloudflare Access

Use Cloudflare Access to control access to Moodle’s API. Configure authentication rules based on enterprise user groups.

2. Access Protection with Caddy

Install Caddy to replace Nginx and integrate internal authentication:

# Install Caddy
sudo curl -s https://getcaddy.com | bash -s personal

# Create Caddyfile
cat << EOF > /etc/caddy/Caddyfile
moodle.yourcompany.com {
    reverse_proxy moodle:80
    tls {
        on_demand
    }
}
EOF

3. Secure Data Storage

Ensure the moodledata directory is stored on a secure storage system, with regular backups and access controls. Use DPTCloud’s network security and 99.98% SLA infrastructure to protect against network attacks.

Verification and Testing

After deployment, verify:

  • Access https://moodle.yourcompany.com to confirm Moodle is operational
  • Run docker-compose ps to check the status of all containers
  • Test SSL using openssl s_client -connect moodle.yourcompany.com:443
  • Test access to Moodle’s API to verify Cloudflare Access authentication

Troubleshooting

  • Cannot access Moodle: Check firewall settings, ports 80/443, and DNS configuration.
  • SSL certificate errors: Run certbot renew or verify Nginx/Caddy configuration.
  • API not working: Verify Cloudflare Access configuration and JWT validation.

References

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478