Reputation: 1
I am getting error while hitting spring boot api. which is internally calling elastic search implementation
943a3f6186c9 docker.elastic.co/elasticsearch/elasticsearch:7.8.0 '/tini -- /usr/local…' ' 11 minutes ago Up 11 minutes 127.0.0.1:9200->9200/tcp, 9300/tcp es01
202627ecb7fd docker.elastic.co/kibana/kibana:7.8.0 '/usr/local/bin/dumb…' 11 minutes ago Up 11 minutes 127.0.0.1:5601->5601/tcp kib01
79395c04a8cf backend:latest '/bin/sh -c '/usr/bi…' 11 minutes ago Up 11 minutes 127.0.0.1:8083->8083/tcp bac01
docker-compose.yml looks like :
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- xpack.security.enabled=false
- http.host=0.0.0.0
- transport.host=127.0.0.1
- bootstrap.memory_lock=true
- discovery.type=single-node
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 127.0.0.1:9200:9200
networks:
- elastic
kib01:
image: docker.elastic.co/kibana/kibana:7.8.0
container_name: kib01
ports:
- 127.0.0.1:5601:5601
environment:
ELASTICSEARCH_URL: http://es01:9200
ELASTICSEARCH_HOSTS: http://es01:9200
networks:
- elastic
bac01:
image: backend:latest
container_name: bac01
ports:
- 127.0.0.1:8083:8083
networks:
- elastic
volumes:
data01:
driver: local
networks:
elastic:
driver: bridge
Elastic Search host : localhost:9200 working fine kibana host : localhost:5601 working fine
while accessing spring boot apis. which internally uses elastic search rest high level client implementation fails
Error :
2020-06-24 10:04:36.154 INFO 1 --- [ main] i.d.backend.common.CommonApplication : Starting CommonApplication v0.0.1 on 79395c04a8cf with PID 1 (/backend.jar started by root in /)
2020-06-24 10:04:36.198 INFO 1 --- [ main] i.d.backend.common.CommonApplication : The following profiles are active: docker
2020-06-24 10:04:52.560 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8083 (http)
2020-06-24 10:04:52.915 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-06-24 10:04:52.916 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.17]
2020-06-24 10:04:53.962 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-06-24 10:04:53.963 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 16725 ms
2020-06-24 10:05:02.290 INFO 1 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService 'taskScheduler'
2020-06-24 10:05:03.322 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8083 (http) with context path ''
2020-06-24 10:05:03.377 INFO 1 --- [ main] i.d.backend.common.CommonApplication : Started CommonApplication in 33.48 seconds (JVM running for 37.713)
2020-06-24 10:06:53.178 INFO 1 --- [nio-8083-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-06-24 10:06:53.233 INFO 1 --- [nio-8083-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-06-24 10:06:53.965 INFO 1 --- [nio-8083-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 722 ms
2020-06-24 10:07:00.732 ERROR 1 --- [nio-8083-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: Connection refused] with root cause
java.lang.RuntimeException: Connection refused
at in.device.backend.common.elasticsearch.service.impl.ElasticsearchServiceImpl.save(ElasticsearchServiceImpl.java:80) ~[classes!/:0.0.1]
at in.device.backend.common.persistance.service.impl.ESResultServiceImpl.save(ESResultServiceImpl.java:29) ~[classes!/:0.0.1]
at in.device.backend.common.controller.PerformanceController.getMeta(PerformanceController.java:69) ~[classes!/:0.0.1]
at in.device.backend.common.controller.PerformanceController.pushSuitResults(PerformanceController.java:48) ~[classes!/:0.0.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]
Upvotes: 0
Views: 1379
Reputation: 835
There are few errors -
bac01 container is dependent on es01 and kib01. So, add to bac01 -
depends_on:
- es01
- kib01
kib01 container is dependent on es01. So, add depends_on for es01 in kib01 definition
bac01 container won't be able to access es01 using localhost:9200. Since, localhost refers to the container itself(bac01). Access es01 using http://es01:9200
Upvotes: 2
Reputation: 150
You are starting multiple Docker containers in a network. In this network you address the cotainers via their name like containername:5601
instead of localhost:5601
or 127.0.0.1:5601
. You could make use of a properties file and environment variables to habe different configutations to run your project local or in docker.
Upvotes: 0