Skip to content

Commit 23cefb2

Browse files
committed
Fix configsvr with user/pass env vars on 5.0 & 6.0
1 parent 4e3014f commit 23cefb2

File tree

5 files changed

+85
-30
lines changed

5 files changed

+85
-30
lines changed

4.2/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

4.4/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

5.0/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

6.0/docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-entrypoint.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,21 @@ _parse_config() {
206206
cat >&2 "$jsonConfigFile"
207207
exit 1
208208
fi
209-
jq 'del(.systemLog, .processManagement, .net, .security, .replication)' "$jsonConfigFile" > "$tempConfigFile"
209+
jq 'del(.systemLog, .processManagement, .net, .security, .replication, .sharding)' "$jsonConfigFile" > "$tempConfigFile"
210210
return 0
211211
fi
212212

213213
return 1
214214
}
215+
216+
_isConfigServer() {
217+
_mongod_hack_have_arg --configsvr "$@" || {
218+
_parse_config "$@" \
219+
&& clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \
220+
&& [ "$clusterRole" = 'configsvr' ]
221+
}
222+
}
223+
215224
dbPath=
216225
_dbPath() {
217226
if [ -n "$dbPath" ]; then
@@ -226,11 +235,7 @@ _dbPath() {
226235
fi
227236

228237
if [ -z "$dbPath" ]; then
229-
if _mongod_hack_have_arg --configsvr "$@" || {
230-
_parse_config "$@" \
231-
&& clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")" \
232-
&& [ "$clusterRole" = 'configsvr' ]
233-
}; then
238+
if _isConfigServer "$@"; then
234239
# if running as config server, then the default dbpath is /data/configdb
235240
# https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr
236241
dbPath=/data/configdb
@@ -314,6 +319,12 @@ if [ "$originalArgOne" = 'mongod' ]; then
314319
if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then
315320
_mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}"
316321
fi
322+
# Setting sharding.clusterRole=configsvr requires the mongod instance to be running with replication
323+
# disable configsvr for initial startup (https://github.com/docker-library/mongo/issues/509)
324+
if _isConfigServer "$@"; then
325+
_mongod_hack_ensure_no_arg '--configsvr' "${mongodHackedArgs[@]}"
326+
_mongod_hack_ensure_arg_val '--dbpath' "$dbPath" "${mongodHackedArgs[@]}"
327+
fi
317328

318329
# "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters"
319330
tlsMode='disabled'

0 commit comments

Comments
 (0)