且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从docker容器连接到本地mongodb

更新时间:2022-11-30 11:22:47

在Mac的Docker上,如果mongo在本地主机上运行,​​则可以使用host.docker.internal.您可以将代码读取到mongo主机的env变量中,然后像这样在Dockerfile中进行设置:

On Docker for Mac, you can use host.docker.internal if your mongo is running on your localhost. You could have your code read in an env variable for the mongo host and set it in the Dockerfile like so:

ENV MONGO_HOST "host.docker.internal"

有关更多详细信息,请参见此处 https://docs.docker.com/docker- for-mac/networking/#use-cases-and-aroundarounds

See here for more details on https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds