Hello everyone !
I have a problem to reach the Elasticsearch container from a service inside the docker network. So I'm running a single node instance and If I try to reach from localhost:9202
everything looks good but from the app
service I get a connection refuse ConnectionError: connect ECONNREFUSED 192.168.176.3:9202
. So the hostname es
get resolved but I have no idea why it's refused. I have already spent time googling and make test but nothing. What is puzzling me is that I can reach the db
service. Any idea ?
this is the docker-compose file
version: "3"
services:
app:
build: .
command: sh -c "
npm run migrate-db &&
npm start"
ports:
- $APP_PORT:3000
environment:
- ES_HOST=es
- DB_HOST=db
env_file:
- .env
depends_on:
- db
- es
db:
image: "postgres:latest"
volumes:
- postgres-volume:/usr/share/postgresql/data
ports:
- $PG_PORT:5432
env_file:
- .env
es:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.2
environment:
- xpack.security.enabled=false
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
cap_add:
- IPC_LOCK
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
ports:
- $ES_PORT:9200
- 9300:9300
kibana:
image: docker.elastic.co/kibana/kibana:7.4.0
environment:
- ELASTICSEARCH_HOSTS=http://es:${ES_PORT}
ports:
- $KIBANA_PORT:5601
depends_on:
- es
volumes:
postgres-volume:
driver: local
elasticsearch-data:
driver: local
this is the JavaScript code in case you are wondering
const client = new Client({ node: `http://${env.ES_HOST}:${env.ES_PORT}` });