title: Spring boot app cannot access elasticsearch using docker-compose
body: <p>I am using docker compose to startup elasticsearch and kibana images. Then I am running my spring boot app using idea and it can connect to elastic container without any problem. When I am using docker compose to run them all (elastic, kibana, my own app), my spring app cannot connect elastic as probably it cannot resolve elastic host. Here is my compose file.</p>
  <pre><code>version: '3.7'
  
  services:
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
      container_name: elasticsearch
      environment:
        - xpack.security.enabled=false
        - discovery.type=single-node
      ulimits:
        memlock:
          soft: -1
          hard: -1
        nofile:
          soft: 65536
          hard: 65536
      cap_add:
        - IPC_LOCK
      volumes:
        - elasticsearch-data:/usr/share/elasticsearch/data
      ports:
        - &quot;9200:9200&quot;
        - &quot;9300:9300&quot;
      networks:
        - search
  
    kibana:
      container_name: kibana
      image: docker.elastic.co/kibana/kibana:7.6.2
      environment:
        - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      ports:
        - &quot;5601:5601&quot;
      depends_on:
        - elasticsearch
      networks:
        - search
      
    spring-boot-demo-app:
      image: 'docker.io/library/spring-boot-demo-app:0.0.1-SNAPSHOT'
      container_name: 'spring-boot-demo-app'
      ports:
        - '8081:8081'
      environment:
        - SPRING_PROFILES_ACTIVE=dev
        - ELASTIC-SEARCH-HOST=elasticsearch
        - ELASTIC-SEARCH-PORT=9200
      depends_on:
        - 'elasticsearch'
      restart: always
      links:
        - elasticsearch
      networks:
        - search
  
  volumes:
    elasticsearch-data:
      driver: local
  networks:
    search:
      driver: bridge
  </code></pre>
  <p>My elastic configuration</p>
  <pre><code>@Configuration
  public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
  
      @Value(&quot;${elasticsearch.host}&quot;)
      private String host;
  
      @Value(&quot;${elasticsearch.port}&quot;)
      private int port;
  
      @Override
      public RestHighLevelClient elasticsearchClient() {
          return new RestHighLevelClient(
                  RestClient.builder(new HttpHost(host, port,&quot;http&quot;)));
      }
  }
  </code></pre>
  <p>Exception:</p>
  <pre><code>org.springframework.dao.DataAccessResourceFailureException: http://elasticsearch; nested exception is java.lang.RuntimeException: http://elasticsearch
  </code></pre>
  <p>It looks like it cannot resolve the host. How can I solve this?</p>