简体   繁体   English

无法使用 monstache 使用 URL 连接到 mongodb

[英]Unable to connect to mongodb using URL using monstache

I've been trying to synchronize my mongodb with elastic for two days and I'm going crazy.我一直试图将我的 mongodb 与弹性同步两天,我快疯了。 After many attempts and changes in my dockerfile and in my docker-compose I get this error, but the container with mongodb is up and running.在我的 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        | 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

This is my dockerfile这是我的 dockerfile

FROM golang
ADD build-4.4.0/linux-amd64/monstache /go/bin/monstache
ENTRYPOINT ["monstache", "-mongo-url='mongodb:27018'", "-elasticsearch-url=elasticsearch:9200"]

And this is my docker-compose file这是我的 docker-compose 文件

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

Any idea?任何的想法?

Thanks!谢谢!

Finally, we desist to use monstache, and we use mongo-connector in a python dockerfile to share the data from mongodb to elasticsearch.最后,我们不再使用 monstache,我们在 python dockerfile 中使用mongo-connector将数据从 mongodb 共享到 elasticsearch。

FROM python:3.4.3

RUN pip install 'mongo-connector[elastic5]' && \
  pip install 'elastic2-doc-manager[elastic5]'

I hope this can help to someone.我希望这可以帮助某人。

You have to change 'mongo-url' to -mongo-url='mongodb:27017' , because all your containers are running in docker network and mongodb is available there on port 27017 since this is exposed port.您必须将 'mongo-url' 更改为-mongo-url='mongodb:27017' ,因为您的所有容器都在 docker 网络中运行,并且 mongodb 在端口27017上可用,因为这是公开端口。

And the below block in compose file will also make mongodb available on your host network at port 27018 but that is accessible via your browser in your local machine env, not in docker network.撰写文件中的以下块还将使 mongodb 在您的主机网络上的端口27018上可用,但可以通过本地机器环境中的浏览器访问,而不是在 docker 网络中。

ports: - 27018:27017

This compose file should also work without links.这个撰写文件也应该在没有链接的情况下工作。

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

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

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