我已经实现了一个带有多个服务器和数据库的微服务体系结构。我已经安装了elasticsearch与docker和当我做docker组成,一切似乎运行良好。
不过,我想将elasticsearch与系统中的几个数据库(下面这个示例中的mongodb)集成在一起。如何使用elasticsearch将两个mongodb同步到两个不同的容器中,以便搜索它们?
client:
container_name: client
stdin_open: true
build:
context: ./client
dockerfile: Dockerfile
restart: always
volumes:
- './client:/app'
ports:
- '1000:3000'
environment:
- NODE_ENV=development
- CHOKIDAR_USEPOLLING=true
weatherdb:
container_name: weather-db
image: mongo
restart: always
ports:
- '2002:27017'
volumes:
- ./weather_service/weather_db:/data/db
networks:
- backend
weather-service:
container_name: weather-service
build: ./weather_service
restart: always
ports:
- "1002:3000"
depends_on:
- weatherdb
links:
- elasticsearch
networks:
- backend
newsdb:
container_name: news-db
image: mongo
restart: always
ports:
- '2003:27017'
volumes:
- ./news_service/news_db:/data/db
networks:
- backend
news-service:
container_name: news-service
build: ./news_service
restart: always
ports:
- "1003:3000"
depends_on:
- newsdb
links:
- elasticsearch
networks:
- backend
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.0
container_name: elasticsearch
restart: always
ports:
- 9200:9200
- 9300:9300
environment:
ES_JAVA_OPTS: '-Xms512m -Xmx512m'
network.bind_host: 0.0.0.0
network.host: 0.0.0.0
discovery.type: single-node
volumes:
- ./elasticsearch/esdata:/usr/share/elasticsearch/data
networks:
- backend
1条答案
按热度按时间ny6fqffe1#
只需添加一个
elasticsearch docker section
在任何docker compose文件中并启动它,所有这些都是独立的docker容器,只要它们在主机上的暴露端口不相互干扰,并且您有正确的配置,它就应该工作。有关更多信息,请参阅elasticsearch multi docker installation using docker file。
注意:您没有提到您面临的具体问题,您已经提到了所有ie所有docker容器都在运行文件,因此请详细解释您到底要解决什么问题