diff --git a/3.0/docker-entrypoint.sh b/3.0/docker-entrypoint.sh index 736f1dd1d3..d8f07cb826 100755 --- a/3.0/docker-entrypoint.sh +++ b/3.0/docker-entrypoint.sh @@ -122,6 +122,7 @@ _js_escape() { jq --null-input --arg 'str' "$1" '$str' } +jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json" tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" _parse_config() { if [ -s "$tempConfigFile" ]; then @@ -132,9 +133,8 @@ _parse_config() { if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) # see https://docs.mongodb.com/manual/reference/configuration-options/ - mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" \ - | jq 'del(.systemLog, .processManagement, .net, .security)' \ - > "$tempConfigFile" + mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi @@ -149,7 +149,7 @@ _dbPath() { if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then if _parse_config "$@"; then - dbPath="$(jq '.storage.dbPath' "$tempConfigFile")" + dbPath="$(jq '.storage.dbPath' "$jsonConfigFile")" fi fi @@ -302,6 +302,6 @@ if [ "$originalArgOne" = 'mongod' ]; then unset "${!MONGO_INITDB_@}" fi -rm -f "$tempConfigFile" +rm -f "$jsonConfigFile" "$tempConfigFile" exec "$@" diff --git a/3.2/docker-entrypoint.sh b/3.2/docker-entrypoint.sh index 736f1dd1d3..d8f07cb826 100755 --- a/3.2/docker-entrypoint.sh +++ b/3.2/docker-entrypoint.sh @@ -122,6 +122,7 @@ _js_escape() { jq --null-input --arg 'str' "$1" '$str' } +jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json" tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" _parse_config() { if [ -s "$tempConfigFile" ]; then @@ -132,9 +133,8 @@ _parse_config() { if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) # see https://docs.mongodb.com/manual/reference/configuration-options/ - mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" \ - | jq 'del(.systemLog, .processManagement, .net, .security)' \ - > "$tempConfigFile" + mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi @@ -149,7 +149,7 @@ _dbPath() { if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then if _parse_config "$@"; then - dbPath="$(jq '.storage.dbPath' "$tempConfigFile")" + dbPath="$(jq '.storage.dbPath' "$jsonConfigFile")" fi fi @@ -302,6 +302,6 @@ if [ "$originalArgOne" = 'mongod' ]; then unset "${!MONGO_INITDB_@}" fi -rm -f "$tempConfigFile" +rm -f "$jsonConfigFile" "$tempConfigFile" exec "$@" diff --git a/3.4/docker-entrypoint.sh b/3.4/docker-entrypoint.sh index 736f1dd1d3..d8f07cb826 100755 --- a/3.4/docker-entrypoint.sh +++ b/3.4/docker-entrypoint.sh @@ -122,6 +122,7 @@ _js_escape() { jq --null-input --arg 'str' "$1" '$str' } +jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json" tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" _parse_config() { if [ -s "$tempConfigFile" ]; then @@ -132,9 +133,8 @@ _parse_config() { if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) # see https://docs.mongodb.com/manual/reference/configuration-options/ - mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" \ - | jq 'del(.systemLog, .processManagement, .net, .security)' \ - > "$tempConfigFile" + mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi @@ -149,7 +149,7 @@ _dbPath() { if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then if _parse_config "$@"; then - dbPath="$(jq '.storage.dbPath' "$tempConfigFile")" + dbPath="$(jq '.storage.dbPath' "$jsonConfigFile")" fi fi @@ -302,6 +302,6 @@ if [ "$originalArgOne" = 'mongod' ]; then unset "${!MONGO_INITDB_@}" fi -rm -f "$tempConfigFile" +rm -f "$jsonConfigFile" "$tempConfigFile" exec "$@" diff --git a/3.6/Dockerfile b/3.6/Dockerfile index d68345060d..74ddffd006 100644 --- a/3.6/Dockerfile +++ b/3.6/Dockerfile @@ -88,4 +88,4 @@ COPY docker-entrypoint.sh /usr/local/bin/ ENTRYPOINT ["docker-entrypoint.sh"] EXPOSE 27017 -CMD ["mongod", "--bind_ip_all"] +CMD ["mongod"] diff --git a/3.6/docker-entrypoint.sh b/3.6/docker-entrypoint.sh index a1d14cffe3..98141240c3 100755 --- a/3.6/docker-entrypoint.sh +++ b/3.6/docker-entrypoint.sh @@ -135,6 +135,7 @@ _js_escape() { jq --null-input --arg 'str' "$1" '$str' } +jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json" tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" _parse_config() { if [ -s "$tempConfigFile" ]; then @@ -145,9 +146,8 @@ _parse_config() { if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) # see https://docs.mongodb.com/manual/reference/configuration-options/ - mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" \ - | jq 'del(.systemLog, .processManagement, .net, .security)' \ - > "$tempConfigFile" + mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" + jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" return 0 fi @@ -162,7 +162,7 @@ _dbPath() { if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then if _parse_config "$@"; then - dbPath="$(jq '.storage.dbPath' "$tempConfigFile")" + dbPath="$(jq '.storage.dbPath' "$jsonConfigFile")" fi fi @@ -313,9 +313,21 @@ if [ "$originalArgOne" = 'mongod' ]; then echo fi + # MongoDB 3.6+ defaults to localhost-only binding + haveBindIp= + if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then + haveBindIp=1 + elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then + haveBindIp=1 + fi + if [ -z "$haveBindIp" ]; then + # so if no "--bind_ip" is specified, let's add "--bind_ip_all" + set -- "$@" --bind_ip_all + fi + unset "${!MONGO_INITDB_@}" fi -rm -f "$tempConfigFile" +rm -f "$jsonConfigFile" "$tempConfigFile" exec "$@"