我已经运行了3个docker容器。 app,mongodb和elasticsearch。
当我从app连接到mongodb时,它看起来像这样:
mongoose.connect('mongodb://<name_of_the_container>/<database_name>');
当我尝试从app连接到elasticsearch时,它不起作用:
const esOptions = {
log: 'error'
};
esOptions.host = '3dominatores:9200';
const esClient = new elasticsearch.Client(esOptions);
它在连接时不会出现任何错误,但在我尝试访问elasticsearch时会大声喊叫:Error: No Living connections
。
我的docker-compose.yml看起来像这样:
version: "2"
services:
3dominator:
build: .
image: 3dominator:0.1
container_name: 3dominator
environment:
NODE_ENV: development
DB_ENV: container
ports:
- "3004:3004"
volumes:
- ./src:/app/src
links:
- 3dominatordb
- 3dominatores
3dominatordb:
image: mongo:3.4.1
volumes:
- ./data/mongodb/db:/data/db
ports:
- "27017:27017"
container_name: 3dominatordb
3dominatores:
image: elasticsearch:latest
ports:
- "9200:9200"
- "9300:9300"
environment:
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
networks:
- elk
container_name: 3dominatores
links:
- 3dominatordb
networks:
elk:
driver: bridge
PS:我是docker
和elasticsearch
编辑
我在上面发现了这个错误:
Elasticsearch ERROR: 2017-03-23T15:45:04Z
Error: Request error, retrying
POST http://3dominatores:9200/projects/project/58d3ed8059ff2d001e5ae4a2 => socket hang up
at Log.error (/app/node_modules/elasticsearch/src/lib/log.js:225:56)
at checkRespForFailure (/app/node_modules/elasticsearch/src/lib/transport.js:240:18)
at HttpConnector.<anonymous> (/app/node_modules/elasticsearch/src/lib/connectors/http.js:162:7)
at ClientRequest.wrapper (/app/node_modules/lodash/lodash.js:4968:19)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketOnEnd (_http_client.js:345:9)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
/app/src/models/ProjectModel.js:56
if (err) throw err;
^