我对docker完全不熟悉。我按照this的说明安装了mongodb图表和docker。
当我连接到172.17.0.1时,它说
Unable to connect to MongoDB using the specified URI.
The following error was returned while attempting to connect:
MongoNetworkError: failed to connect to server [172.17.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 172.17.0.1:27017]
The result from pinging the specified server "172.17.0.1" from within the container is:
PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.050 ms
--- 172.17.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.050/0.050/0.050/0.000 msmongodb在本地机器上运行。我认为它没有在容器中运行(不确定),因为我在安装docker之前在我的机器上安装了mongodb。
我还使用docker network inspect bridge检查了设置
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]这是yml文件:
version: "3.3"
services:
charts:
image: quay.io/mongodb/charts:v0.10.0
hostname: charts
ports:
# host:container port mapping. If you want MongoDB Charts to be
# reachable on a different port on the docker host, change this
# to <port>:80, e.g. 8888:80.
- 80:80
- 443:443
volumes:
- keys:/mongodb-charts/volumes/keys
- logs:/mongodb-charts/volumes/logs
- db-certs:/mongodb-charts/volumes/db-certs
- web-certs:/mongodb-charts/volumes/web-certs
environment:
# The presence of following 2 environment variables will enable HTTPS on Charts server.
# All HTTP requests will be redirected to HTTPS as well.
# To enable HTTPS, upload your certificate and key file to the web-certs volume,
# uncomment the following lines and replace with the names of your certificate and key file.
# CHARTS_HTTPS_CERTIFICATE_FILE: charts-https.crt
# CHARTS_HTTPS_CERTIFICATE_KEY_FILE: charts-https.key
# This environment variable controls the built-in support widget and
# metrics collection in MongoDB Charts. To disable both, set the value
# to "off". The default is "on".
CHARTS_SUPPORT_WIDGET_AND_METRICS: "on"
# Directory where you can upload SSL certificates (.pem format) which
# should be considered trusted self-signed or root certificates when
# Charts is accessing MongoDB servers with ?ssl=true
SSL_CERT_DIR: /mongodb-charts/volumes/db-certs
networks:
- backend
secrets:
- charts-mongodb-uri
networks:
backend:
volumes:
keys:
logs:
db-certs:
web-certs:
secrets:
charts-mongodb-uri:
external: true如何连接mongodb?
发布于 2020-09-03 01:22:13
默认情况下,mongodb被配置为只接受来自本地主机127.0.0.1的结果,当图表图像通过docker连接到它时,它被视为来自docker0的外部连接,因此被mongodb拒绝。mongodb被配置为只接受来自本地主机127.0.0.1的结果
要解决此问题,请编辑mongo配置sudo vim /etc/mongod.conf,并将您的docker0 ip添加到bindIp配置中。对于默认docker安装,应将带有bindIp: 127.0.0.1的行更改为bindIp: 127.0.0.1,172.17.0.1。
这可能是一个古老的问题,但我认为这可能是一个常见的问题,在真正更彻底地阅读错误消息并意识到它确实是一个简单的问题之前,我不得不与此斗争了一段时间。
另一个问题是,在第一次安装时,您可以在没有用户名或密码的情况下连接到mongo,因此,如果您没有配置安全性,则应该从uri中删除这两个,使其成为mongodb://172.17.0.1:27017.。
发布于 2018-11-11 08:45:08
假设您知道如何使用echo "mongodb://<username>:<password>@myhost.com/" | docker secret create charts-mongodb-uri -创建连接,请查看url。
问题实际上是如何从docker容器连接到主机上运行的外部服务。你可以从像From inside of a Docker container, how do I connect to the localhost of the machine?这样的大量问题中获得一些帮助
基本上,如果您正在使用docker for mac或windows,请使用类似于echo "mongodb://host.docker.internal" | docker secret create charts-mongodb-uri -、for linux参见https://docs.mongodb.com/charts/master/installation/部分RUNNING METADATA DATABASE ON LOCALHOST的文档,或者直接使用主机模式(删除端口部分)。
version: "3.3"
services:
charts:
image: quay.io/mongodb/charts:v0.10.0
hostname: charts
network_mode: "host"
...https://stackoverflow.com/questions/53240613
复制相似问题