docker-composecontainersupgrademoodlebitnami

Upgrading bitnami/moodle container


I have a setup based on what is described in https://hub.docker.com/r/bitnami/moodle

# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

version: '2'
services:
  mariadb:
    image: docker.io/bitnami/mariadb:11.3
    environment:
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_USER=bn_moodle
      - MARIADB_DATABASE=bitnami_moodle
      - MARIADB_CHARACTER_SET=utf8mb4
      - MARIADB_COLLATE=utf8mb4_unicode_ci
    volumes:
      - ./mariadb_data:/bitnami/mariadb
  moodle:
    image: docker.io/bitnami/moodle:4.3
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_PORT_NUMBER=3306
      - MOODLE_DATABASE_USER=bn_moodle
      - MOODLE_DATABASE_NAME=bitnami_moodle
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - ./moodle_data:/bitnami/moodle
      - ./moodledata_data:/bitnami/moodledata
    depends_on:
      - mariadb

The moodle version in site administration - notifications: Moodle 4.3.2 (Build: 20231222)

I want to upgrade the moodle instance to moodle:4.4 and for some reason thought it'd be as simple as updating the docker-compose.yml and restarting the stack. But, it does seem that there is much to do and I don't quite understand how to do this.

I also noticed that I would like to have all the language versions available so I created Dockerfile with only FROM bitnami/moodle and docker-compose.yml

# Copyright Broadcom, Inc. All Rights Reserved.
# SPDX-License-Identifier: APACHE-2.0

version: '2'
services:
  mariadb:
    image: docker.io/bitnami/mariadb:11.3
    environment:
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
      - MARIADB_USER=bn_moodle
      - MARIADB_DATABASE=bitnami_moodle
      - MARIADB_CHARACTER_SET=utf8mb4
      - MARIADB_COLLATE=utf8mb4_unicode_ci
    volumes:
      - ./mariadb_data:/bitnami/mariadb
  moodle:
    #image: docker.io/bitnami/moodle:4.4
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - WITH_ALL_LOCALES=yes
    ports:
      - '80:8080'
      - '443:8443'
    environment:
      - MOODLE_DATABASE_HOST=mariadb
      - MOODLE_DATABASE_PORT_NUMBER=3306
      - MOODLE_DATABASE_USER=bn_moodle
      - MOODLE_DATABASE_NAME=bitnami_moodle
      # ALLOW_EMPTY_PASSWORD is recommended only for development.
      - ALLOW_EMPTY_PASSWORD=yes
    volumes:
      - ./moodle_data:/bitnami/moodle
      - ./moodledata_data:/bitnami/moodledata
    depends_on:
      - mariadb

Could someone provide a step-by-step instructions how I get from old setup to new setup without losing my data?


Solution

  • I treat the upgrade as a "restore from backup" procedure

    I've done this a couple of times and not had any issues yet. Here are my steps. Note:

    Step 1: Back up your moodledata and database

    dc exec mariadb mariadb-dump -u bn_moodle bitnami_moodle > "${BACKUP_DIR}/backup.sql"
    docker cp -a docker-compose-moodle-1:/bitnami/moodledata "${BACKUP_DIR}"
    

    Step 2: Launch a new compose stack with your desired version

    # Copy your docker-compose.yml to a new directory
    cp <project-dir> <new-project-dir>
    cd <new-project-dir>
    
    # NB: Change the external port to a new port to avoid conflict if on the same host
    
    # Start the docker-compose and check the logs
    # NB wait for initial install to complete
    dc up -d && dc logs -f
    

    Step 3a: Restore the DB (change to match your auth)

    # Clear the DB.
    dc exec mariadb mariadb -u bn_moodle -e 'drop database bitnami_moodle; create database bitnami_moodle' 
    # Load the snapshot DB into the docker mariadb
    dc exec -T mariadb mariadb -u bn_moodle -D bitnami_moodle < ${BACKUP_DIR}/backup.sql
    

    Step 3b: Copy in your "moodledata" and set file permissions

    # get the name of your **new** <moodle-container>
    docker ps
    
    # Copy in the "moodledata"
    docker cp -a ${BACKUP_DIR}/moodledata <moodle-container>:/bitnami/
    
    # Update the file permissions
    dc exec moodle chown -R daemon:daemon /bitnami/moodledata/
    

    Step 4: Redirect traffic to the new instance

    Step 5: Log in to the site as admin. The upgrade window should display. Follow the instructions to upgrade

    Step 5 (alternative): Restart the moodle container and view the logs. It should auto-upgrade. I don't like this because I can't see what is happening.

    Issues with this approach

    NOTE: