Skip to content

Commit 1cc9a7a

Browse files
stronk7abias
authored andcommitted
MOODLE_DOCKER_WEB_PORT to control both bind_ip and port #66
This solves #64 Truth table: not set (dflt) ==> 127.0.0.1:8000 0 ==> 0 (means no web server is started) 999 ==> 127.0.0.1:999 0.0.0.0:999 ==> 0.0.0.0.999
1 parent 0fc0f32 commit 1cc9a7a

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ You can change the configuration of the docker images by setting various environ
132132
| `MOODLE_DOCKER_BROWSER` | no | firefox, chrome | firefox | The browser to run Behat against |
133133
| `MOODLE_DOCKER_PHPUNIT_EXTERNAL_SERVICES` | no | any value | not set | If set, dependencies for memcached, redis, solr, and openldap are added |
134134
| `MOODLE_DOCKER_WEB_HOST` | no | any valid hostname | localhost | The hostname for web |
135-
| `MOODLE_DOCKER_WEB_PORT` | no | any integer value | 8000 | The port number for web. If set to 0, no port is used |
135+
| `MOODLE_DOCKER_WEB_PORT` | no | any integer value (or bind_ip:integer)| 127.0.0.1:8000| The port number for web. If set to 0, no port is used.<br/>If you want to bind to any host IP different from the default 127.0.0.1, you can specify it with the bind_ip:port format (0.0.0.0 means bind to all) |
136136
| `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 |
137137

138138
## Advanced usage

bin/moodle-docker-compose

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ export MOODLE_DOCKER_WEB_HOST=${MOODLE_DOCKER_WEB_HOST:-localhost}
6969

7070
# Webserver port
7171
export MOODLE_DOCKER_WEB_PORT=${MOODLE_DOCKER_WEB_PORT:-8000}
72-
if [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]]
72+
if [[ $MOODLE_DOCKER_WEB_PORT == *":"* ]] || [[ $MOODLE_DOCKER_WEB_PORT -gt 0 ]]
7373
then
74+
# If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
75+
if [[ ! $MOODLE_DOCKER_WEB_PORT == *":"* ]]
76+
then
77+
MOODLE_DOCKER_WEB_PORT=127.0.0.1:$MOODLE_DOCKER_WEB_PORT
78+
fi
7479
dockercompose="${dockercompose} -f ${basedir}/webserver.port.yml"
7580
fi
7681

bin/moodle-docker-compose.cmd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,14 @@ IF "%MOODLE_DOCKER_WEB_PORT%"=="" (
5252
SET MOODLE_DOCKER_WEB_PORT=8000
5353
)
5454

55-
IF NOT "%MOODLE_DOCKER_WEB_PORT%"=="0" (
55+
SET "TRUE="
56+
IF NOT "%MOODLE_DOCKER_WEB_PORT%"=="%MOODLE_DOCKER_WEB_PORT::=%" SET TRUE=1
57+
IF NOT "%MOODLE_DOCKER_WEB_PORT%"=="0" SET TRUE=1
58+
IF DEFINED TRUE (
59+
REM If no bind ip has been configured (bind_ip:port), default to 127.0.0.1
60+
IF "%MOODLE_DOCKER_WEB_PORT%"=="%MOODLE_DOCKER_WEB_PORT::=%" (
61+
SET MOODLE_DOCKER_WEB_PORT=127.0.0.1:%MOODLE_DOCKER_WEB_PORT%
62+
)
5663
SET DOCKERCOMPOSE=%DOCKERCOMPOSE% -f "%BASEDIR%\webserver.port.yml"
5764
)
5865

config.docker-template.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
$CFG->wwwroot = "http://{$host}";
2121
$port = getenv('MOODLE_DOCKER_WEB_PORT');
2222
if (!empty($port)) {
23-
$CFG->wwwroot .= ":{$port}";
23+
// Extract port in case the format is bind_ip:port.
24+
$parts = explode(':', $port);
25+
$port = end($parts);
26+
if ((string)(int)$port === (string)$port) { // Only if it's int value.
27+
$CFG->wwwroot .= ":{$port}";
28+
}
2429
}
2530
$CFG->dataroot = '/var/www/moodledata';
2631
$CFG->admin = 'admin';

0 commit comments

Comments
 (0)