简体   繁体   English

无法从主机连接到Docker容器中的MongoDB。

[英]Cannot connect to MongoDB in Docker container from the host machine.

I have following image: 我有以下图像:

FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install apt-transport-https -y
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.6.list
RUN apt-get update
RUN apt-get install -y mongodb-org=3.6.2 mongodb-org-server=3.6.2 mongodb-org-shell=3.6.2 mongodb-org-mongos=3.6.2 mongodb-org-tools=3.6.2
RUN mkdir -p /data/db
EXPOSE 27017
CMD ["--port 27017", "--smallfiles"]
ENTRYPOINT usr/bin/mongod

Run it with: 使用以下命令运行它:

docker run --rm -ti --security-opt=seccomp:unconfined -p27017:27017 -p28017:28017 --name mong --rm mong 码头工人运行--rm -ti --security-opt = seccomp:unconfined -p27017:27017 -p28017:28017 --name mong --rm mong

I see following Warning after run it: 运行它后,我看到以下警告:

WARNING: This server is bound to localhost.
Remote systems will be unable to connect to this server.
Start the server with --bind_ip <address> to specify which IP
addresses it should serve responses from, or with --bind_ip_all to
bind to all interfaces. If this behavior is desired, start the
server with --bind_ip 127.0.0.1 to disable this warning.

I tried to add CMD ["--bind_ip_all"] right before entrypoint but it didn't help. 我试图在入口点之前添加CMD ["--bind_ip_all"] ,但这没有帮助。 How to expose MongoDB to hostmachine? 如何将MongoDB暴露给主机?

Try with: --bind_ip 0.0.0.0 尝试:-- --bind_ip 0.0.0.0

Your CMD becomes: 您的CMD变为:

CMD ["--port 27017", "--smallfiles", "--bind_ip", "0.0.0.0"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM