gpt4 book ai didi

mongodb - 如何在 mongo db 配置文件 (mongod.conf) 中使用环境变量作为 Bind-Ip

转载 作者:行者123 更新时间:2023-12-02 20:04:14 25 4
gpt4 key购买 nike

我是 mongodb 的新手,据我所知,我们总是在 mongod.conf 文件中将 127.0.0.1 或 172.17.0.5 等常量 IP 值作为绑定(bind) IP 传递。

这是我的 mongod.conf 中的绑定(bind) ip 配置>

net:
port: 27017
bindIp: 127.0.0.1, 172.17.0.5 # Listen to local interface only, comment to listen on all interfaces.

我在/etc/environment 文件中定义了一个环境变量
DHOST = 172.17.0.5

当我尝试在 mongod.conf 中提供以下配置时,我无法连接到 mongo shell:
net:
port: 27017
bindIp: 127.0.0.1, *$DHOST* # Listen to local interface only, comment to listen on all interfaces.

请帮我在 mongo db 配置中添加一个 ENV var 作为绑定(bind) ip

最佳答案

对于在 Docker 容器中运行的东西,您几乎应该总是绑定(bind)到 IPv4 0.0.0.0 或 IPv6::0(即“所有地址”)。 docker run -p option 有一个可选字段,可以限制已发布端口将绑定(bind)到的主机上的 IP 地址;如果没有这样的配置,就无法直接从主机外访问容器,因此尝试绑定(bind)到容器内的特定接口(interface)并不是特别有用。

关于mongodb - 如何在 mongo db 配置文件 (mongod.conf) 中使用环境变量作为 Bind-Ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51156750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com