无法使用使用Monstach的URL连接到mongodb
两天来,我一直在尝试将我的mongodb与elastic同步,我快疯了。 在我的dockerfile和docker compose中进行了多次尝试和更改之后,我得到了这个错误,但是带有mongodb的容器已经启动并运行无法使用使用Monstach的URL连接到mongodb,mongodb,docker,elasticsearch,Mongodb,Docker,elasticsearch,两天来,我一直在尝试将我的mongodb与elastic同步,我快疯了。 在我的dockerfile和docker compose中进行了多次尝试和更改之后,我得到了这个错误,但是带有mongodb的容器已经启动并运行 monstache | ERROR 2018/07/27 17:59:07 Unable to connect to mongodb using URL 'mongodb:27018': no reachable servers monstache |
monstache | ERROR 2018/07/27 17:59:07 Unable to connect to mongodb using URL 'mongodb:27018': no reachable servers
monstache | panic: Unable to connect to mongodb using URL 'mongodb:27018': no reachable servers
monstache |
monstache | goroutine 1 [running]:
monstache | log.(*Logger).Panicf(0xc420020c30, 0xd4fc15, 0x2d, 0xc42006fc18, 0x2, 0x2)
monstache | /usr/local/go/src/log/log.go:219 +0xdb
monstache | main.main()
monstache | /home/vagrant/go/src/github.com/rwynn/monstache/monstache.go:2400 +0x320
monstache exited with code 2
这是我的文件
FROM golang
ADD build-4.4.0/linux-amd64/monstache /go/bin/monstache
ENTRYPOINT ["monstache", "-mongo-url='mongodb:27018'", "-elasticsearch-url=elasticsearch:9200"]
这是我的docker撰写文件
version: '3.3'
services:
mongodb:
image: mongo
restart: always
container_name: mongodb
volumes:
- ./data/mongodb:/usr/share/mongodb/data
ports:
- 27018:27017
elasticsearch:
image: elasticsearch
restart: always
container_name: elasticsearch
volumes:
- ./data/elastic:/usr/share/elasticsearch/data
ports:
- 9200:9200
monstache:
build: ./monstache/
restart: always
container_name: monstache
links:
- elasticsearch
- mongodb
有什么想法吗
谢谢 您必须将“mongo url”更改为
-mongo url='mongodb:27017'
,因为您的所有容器都在docker网络中运行,并且mongodb在端口27017
上可用,因为这是公开的端口
compose文件中的下一块也将使mongodb在主机网络上的端口27018
可用,但可通过本地机器环境中的浏览器访问,而不是在docker网络中
端口:
-27018:27017
此撰写文件也应在没有链接的情况下工作
版本:“3.3”
服务:
mongodb:
图片:mongo
重新启动:始终
容器名称:mongodb
卷数:
-./data/mongodb:/usr/share/mongodb/data
端口:
- 27018:27017
弹性搜索:
图片:elasticsearch
重新启动:始终
容器名称:elasticsearch
卷数:
-./data/elastic:/usr/share/elasticsearch/data
端口:
- 9200:9200
小胡子:
身材:/小胡子/
重新启动:始终
容器名称:Monstach
最后,我们不再使用Monstach,而是在python dockerfile中使用它来共享mongodb到elasticsearch的数据
FROM python:3.4.3
RUN pip install 'mongo-connector[elastic5]' && \
pip install 'elastic2-doc-manager[elastic5]'
我希望这能对其他人有所帮助。请在这里更新docker compose文件好吗?提前谢谢。我用我使用的解决方案升级了它。我希望这对你有帮助。mongo-connector已经过时了