Skip to content

Commit

Permalink
Support a connection to an external DB
Browse files Browse the repository at this point in the history
  • Loading branch information
scara committed Nov 13, 2022
1 parent 1f0a5bc commit 95b584c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,33 @@ When you change them, use `bin/moodle-docker-compose down && bin/moodle-docker-c
| `MOODLE_DOCKER_APP_VERSION` | no | a valid [app docker image version](https://docs.moodle.org/dev/Moodle_App_Docker_images) | not set | If set will start an instance of the Moodle app if the chrome browser is selected |
| `MOODLE_DOCKER_APP_RUNTIME` | no | 'ionic3' or 'ionic5' | not set | Set this to indicate the runtime being used in the Moodle app. In most cases, this can be ignored because the runtime is guessed automatically (except on Windows using the `.cmd` binary). In case you need to set it manually and you're not sure which one it is, versions 3.9.5 and later should be using Ionic 5. |

## Use an external database

You can use an external database by setting `MOODLE_DOCKER_DB*` internal environment variables.

For example to connect to an external DB server hosted in Azure:

```
# Configure coordinates and credentials for the external DB instance.
export MOODLE_DOCKER_DBHOST=instance-name.mysql.database.azure.com
export MOODLE_DOCKER_DBNAME=moodle-external-db
export MOODLE_DOCKER_DBUSER=instance-username
export MOODLE_DOCKER_DBPASS="1nst@nc3-p@ssw0rd"
# Start the docker environment.
bin/moodle-docker-compose up -d
...
# Stop the docker environemnt.
bin/moodle-docker-compose down
# Unset the external DB instance refs.
unset MOODLE_DOCKER_DBHOST MOODLE_DOCKER_DBNAME MOODLE_DOCKER_DBUSER MOODLE_DOCKER_DBPASS
```

Please note that the local DB server will be still available to allow e.g. the usage of the specific DB client to connect to the remote DB server:

```
bin/moodle-docker-compose exec db mysql -h instance-name.mysql.database.azure.com -u ******** -p'********' -e "SELECT VERSION();"
```

## Using XDebug for live debugging

The XDebug PHP Extension is not included in this setup and there are reasons not to include it by default.
Expand Down
1 change: 1 addition & 0 deletions base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- "${MOODLE_DOCKER_WWWROOT}:/var/www/html"
- "${ASSETDIR}/web/apache2_faildumps.conf:/etc/apache2/conf-enabled/apache2_faildumps.conf"
environment:
MOODLE_DOCKER_DBHOST: db
MOODLE_DOCKER_DBNAME: moodle
MOODLE_DOCKER_DBUSER: moodle
MOODLE_DOCKER_DBPASS: "m@0dl3ing"
Expand Down
2 changes: 1 addition & 1 deletion config.docker-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$CFG->dbtype = getenv('MOODLE_DOCKER_DBTYPE');
$CFG->dblibrary = 'native';
$CFG->dbhost = 'db';
$CFG->dbhost = getenv('MOODLE_DOCKER_DBHOST');
$CFG->dbname = getenv('MOODLE_DOCKER_DBNAME');
$CFG->dbuser = getenv('MOODLE_DOCKER_DBUSER');
$CFG->dbpass = getenv('MOODLE_DOCKER_DBPASS');
Expand Down

0 comments on commit 95b584c

Please sign in to comment.