Skip to content

Commit 571f6ba

Browse files
committed
Allow integrating docker containers in traefik
1 parent 6a84650 commit 571f6ba

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ You can change the configuration of the docker images by setting various environ
130130
| `MOODLE_DOCKER_WEB_HOST` | no | any valid hostname | localhost | The hostname for web |
131131
| `MOODLE_DOCKER_WEB_PORT` | no | any integer value | 8000 | The port number for web. If set to 0, no port is used |
132132
| `MOODLE_DOCKER_SELENIUM_VNC_PORT` | no | any integer value | not set | If set, the selenium node will expose a vnc session on the port specified |
133+
| `MOODLE_DOCKER_TRAEFIK` | no | any value | not set | If set, integrate the docker containers in traefik |
133134

134135
## Advanced usage
135136

bin/moodle-docker-compose

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ dockercompose="${dockercompose} -f ${basedir}/service.mail.yml"
3131
# PHP Version.
3232
export MOODLE_DOCKER_PHP_VERSION=${MOODLE_DOCKER_PHP_VERSION:-7.1}
3333

34+
# Enable Traefik
35+
if [ -n "$MOODLE_DOCKER_TRAEFIK" ];
36+
then
37+
dockercompose="${dockercompose} -f ${basedir}/traefik.yml"
38+
fi
39+
3440
# Database flavour
3541
if [ "$MOODLE_DOCKER_DB" != 'pgsql' ];
3642
then
@@ -69,7 +75,7 @@ export MOODLE_DOCKER_WEB_HOST=${MOODLE_DOCKER_WEB_HOST:-localhost}
6975

7076
# Webserver port
7177
export MOODLE_DOCKER_WEB_PORT=${MOODLE_DOCKER_WEB_PORT:-8000}
72-
if [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]]
78+
if [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]] && [ -z "$MOODLE_DOCKER_TRAEFIK" ]
7379
then
7480
dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml"
7581
fi

config.docker-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
$CFG->wwwroot = "http://{$host}";
2121
$port = getenv('MOODLE_DOCKER_WEB_PORT');
22-
if (!empty($port)) {
22+
if (!empty($port) && empty(getenv('MOODLE_DOCKER_TRAEFIK'))) {
2323
$CFG->wwwroot .= ":{$port}";
2424
}
2525
$CFG->dataroot = '/var/www/moodledata';

traefik.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "2"
2+
services:
3+
webserver:
4+
environment:
5+
MOODLE_DOCKER_TRAEFIK: "${MOODLE_DOCKER_TRAEFIK}"
6+
labels:
7+
- "traefik.enable=true"
8+
- "traefik.frontend.rule=Host:${MOODLE_DOCKER_WEB_HOST}"
9+
- 'traefik.docker.network=traefik_default'
10+
networks:
11+
- default
12+
- traefik
13+
exttests:
14+
networks:
15+
- default
16+
- traefik
17+
selenium:
18+
networks:
19+
- default
20+
- traefik
21+
22+
networks:
23+
default:
24+
traefik:
25+
external:
26+
name: traefik_default

0 commit comments

Comments
 (0)