# High level rest client facing Connection refused when running docker image

**URL:** https://discuss.elastic.co/t/high-level-rest-client-facing-connection-refused-when-running-docker-image/203187
**Category:** Elasticsearch
**Created:** [October 11, 2019, 8:52am UTC](https://discuss.elastic.co/t/high-level-rest-client-facing-connection-refused-when-running-docker-image/203187 "2019-10-11T08:52:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tutorj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tutorj/32/55766_2.png) [@tutorj](https://discuss.elastic.co/u/tutorj)
#### Post date: [October 11, 2019, 8:52am UTC](https://discuss.elastic.co/t/high-level-rest-client-facing-connection-refused-when-running-docker-image/203187/1 "2019-10-11T08:52:18Z")

</div>

Dear community,

I'm new to elastic & i'm trying to cloud-ize my application via docker then kubernetes.  
I've built the same Springboot app as:

> **[How to use Java High Level Rest Client with Spring Boot to talk to AWS...](https://medium.com/@sourav.pati09/how-to-use-java-high-level-rest-client-with-spring-boot-to-talk-to-aws-elasticsearch-2b6106f2e2c)**
>
> Recently, for one of my projects, I needed to use Elasticsearch running on AWS Elasticsearch Service domain. When I created the cluster in…

To test this app:  
**1. Pull docker image**  
a. docker pull [docker.elastic.co/elasticsearch/elasticsearch:6.8.2](http://docker.elastic.co/elasticsearch/elasticsearch:6.8.2)  
b. docker pull [docker.elastic.co/elasticsearch/kibana:6.8.2](http://docker.elastic.co/elasticsearch/kibana:6.8.2)

**2. Run image on docker**  
a. docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" [docker.elastic.co/elasticsearch/elasticsearch:6.8.2](http://docker.elastic.co/elasticsearch/elasticsearch:6.8.2)  
b. docker run --link :elasticsearch -p 5601:5601 [docker.elastic.co/kibana/kibana:6.8.2](http://docker.elastic.co/kibana/kibana:6.8.2)

**3. both locahost:9200 & 5601 are ping-able**

**4. mvn package app into jar & run it**  
java -jar elastic-client-0.0.1-LOCAL.jar

**4.5. application.properties**  
elasticsearch.host=http://localhost:9200

**5. CRUD successful via curl or "postman" (a restful client) works too**

**6. build docker image successfully then push to private repo by:**  
docker build -t hironwayj/elastic-client-local .  
docker push hironwayj/elastic-client-local

here's my dockerfile:  
FROM maven:3.5-jdk-8-alpine as builder  
WORKDIR /app  
COPY pom.xml .  
COPY src ./src  
RUN mvn package -DskipTests  
FROM openjdk:8-jre-alpine  
COPY --from=builder /app/target/elastic-client-0.0.1-LOCAL.jar /elastic-client-local.jar  
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/elastic-client-local.jar"]

**7. run docker image**  
docker run -p 8080:8080 hironwayj/elastic-client-local

**8. Failed when CRUD with connection refused**  
java.net.ConnectException: Connection refused  
at org.elasticsearch.client.RestClient$SyncResponseListener.get(RestClient.java:943) ~[elasticsearch-rest-client-6.4.3.jar!/:6.8.2]  
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:227) ~[elasticsearch-rest-client-6.4.3.jar!/:6.8.2]  
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1764) ~[elasticsearch-rest-high-level-client-6.8.2.jar!/:6.8.2]  
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1734) ~[elasticsearch-rest-high-level-client-6.8.2.jar!/:6.8.2]  
at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1696) ~[elasticsearch-rest-high-level-client-6.8.2.jar!/:6.8.2]  
at org.elasticsearch.client.RestHighLevelClient.search(RestHighLevelClient.java:1092) ~[elasticsearch-rest-high-level-client-6.8.2.jar!/:6.8.2]  
at com.hackthon.tk.elasticclient.service.ProfileService.findAllProfile(ProfileService.java:70) ~[classes!/:0.0.1-LOCAL]  
at com.hackthon.tk.elasticclient.controller.ProfileController.findAll(ProfileController.java:40) ~[classes!/:0.0.1-LOCAL]

**Did i configure somewhere wrong? Why is java -jar runnable while failed in docker image?**

Thank you so much!

---

<div class="post-metadata">

### Author: ![tutorj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tutorj/32/55766_2.png) [@tutorj](https://discuss.elastic.co/u/tutorj)
#### Post date: [October 15, 2019, 7:20am UTC](https://discuss.elastic.co/t/high-level-rest-client-facing-connection-refused-when-running-docker-image/203187/2 "2019-10-15T07:20:19Z")

</div>

The problem has been solved, thanks a lot!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 12, 2019, 7:20am UTC](https://discuss.elastic.co/t/high-level-rest-client-facing-connection-refused-when-running-docker-image/203187/3 "2019-11-12T07:20:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
