I have a spring boot application which uses elasticsearch db and mongodb. I want to dockerize this on a docker-container for which I have written a docker-compose yml file which is given below
version : "3"
services:
eswmongodb:
image: mongo:latest
container_name: mongocont
ports:
- "27017:27017"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
container_name: elasticsearch
environment:
- node.name=elasticsearch
- discovery.type=single-node
- cluster.name=docker-cluster
ports:
- "9200:9200"
- "9300:9300"
esw:
image: esw
container_name: eswrapper
ports:
- "8071:8071"
links:
- elasticsearch
- eswmongodb
Only mongodb is getting connected with the spring boot application and I am able to access that but when I am hitting an api which uses a elasticsearch. I get an error as
Occurred with exception:[Connection refused]
java.net.ConnectException: Connection refused
I have supplied the necessary information in application.properties file.
spring.data.elasticsearch.cluster-node=elasticsearch:9200
spring.data.elasticsearch.cluster-name=docker-cluster
spring.data.mongodb.uri=mongodb://eswmongodb:27017/esw
Any thoughts why elasticsearch is not able to get connected. I have seen earlier answers provided in stack-overflow but the issue still persists.
All container are showing running.
Also tried spring.data.elasticsearch.cluster-nodes this property but this becomes disable so I went with spring.data.elasticsearch.cluster-node.
I have also added the actual exception present in logs when I hit an api endpoint which uses elastic search for further help if required.
2022-01-04 13:44:45,354 | ERROR | TxId=1641303885129000010435 |
IndexOperationsImpl.createIndexWithCustomSettingAndMapping:62 |
Exception Occurred with exception:[Connection refused]
java.net.ConnectException: Connection refused at
org.elasticsearch.client.RestClient.
extractAndWrapCause(RestClient.java:849)
at org.elasticsearch.client.RestClient.
performRequest(RestClient.java:259)
at org.elasticsearch.client.RestClient.
performRequest(RestClient.java:246)
Some logs of elasticsearch container when hitting docker-compose logs elasticsearch
Attaching to elasticsearch
elasticsearch | {"type": "server", "timestamp": "2022-01-
04T16:03:59,187Z", "level": "INFO", "component": "o.e.n.Node",
"cluster.name": "docker-cluster", "node.name": "elasticsearch",
"message": "version[7.9.3], pid[7],
[default/docker/c4138e51121ef06a6404866cddc601906fe5c868/2020
10-16T13:34:25.304557Z], OS[Linux/5.10.25-linuxkit/aarch64],
JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/15/15+36-1562]" }
elasticsearch | {"type": "server", "timestamp": "2022-01-
04T16:03:59,189Z", "level": "INFO", "component": "o.e.n.Node",
"cluster.name": "docker-cluster", "node.name": "elasticsearch",
"message": "JVM home [/usr/share/elasticsearch/jdk]" }
links:is an obsolete and unnecessary Compose option, and it might interfere with the networking setup. Does removing thelinks:block (or changing it todepends_on:) help? Is the application starting up before Elasticsearch is available?