且构网

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

从 docker 容器连接到本地 mongodb

更新时间:2022-11-30 11:36:07

在 Docker for Mac 上,如果你的 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-workarounds