# Failed to connect to localhost port 9200: Connection refused

**URL:** <https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [August 9, 2024, 5:59pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710 "2024-08-09T17:59:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edzel\_Severino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edzel_severino/32/136690_2.png) [@Edzel\_Severino](https://discuss.elastic.co/u/Edzel_Severino)\
**Post date:** [August 9, 2024, 5:59pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/1 "2024-08-09T17:59:59Z")

</div>

Can someone help me? I followed a link on installing elastic,kibana and logstash and i was able to successfully installed elastic. However, when i try to netstat and look for the port 9200, it wasnt there. Also I can't curl the localhost:9200 saying connection refused.

---

<div class="post-metadata">

**Author:** ![Edzel\_Severino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edzel_severino/32/136690_2.png) [@Edzel\_Severino](https://discuss.elastic.co/u/Edzel_Severino)\
**Post date:** [August 9, 2024, 6:01pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/2 "2024-08-09T18:01:38Z")

</div>

this is my .yml via docker

```auto
version: "3"
services:
  setup:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.1
    environment:
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - KIBANA_PASSWORD=${KIBANA_PASSWORD}
    container_name: setup
    command:
      - bash
      - -c
      - |
        echo "Waiting for Elasticsearch availability";
        until curl -s http://elasticsearch:9200 | grep -q "missing authentication credentials"; do sleep 30; done;
        echo "Setting kibana_system password";
        until curl -s -X POST -u "elastic:${ELASTIC_PASSWORD}" -H "Content-Type: application/json" http://elasticsearch:9200/_security/user/kibana_system/_password -d "{\"password\":\"${KIBANA_PASSWORD}\"}" | grep -q "^{}"; do sleep 10; done;
        echo "All done!";

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.12.1
    # give the container a name
    # this will also set the container's hostname as elasticsearch
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - cluster.name=elasticsearch
      - bootstrap.memory_lock=true
      # limits elasticsearch to 1 GB of RAM
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      # The password for the 'elastic' user
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - xpack.security.http.ssl.enabled=false

  kibana:
    image: docker.elastic.co/kibana/kibana:8.12.1
    container_name: kibana
    ports:
      - 5601:5601
    environment:
      # remember the container_name for elasticsearch?
      # we use it here to access that container
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200
      - ELASTICSEARCH_USERNAME=kibana_system
      - ELASTICSEARCH_PASSWORD=${KIBANA_PASSWORD}
      # Change this to true if you want to sent
      # telemetry data to kibana developers
      - TELEMETRY_ENABLED=false

```

```auto
  logstash:
    image: docker.elastic.co/logstash/logstash:8.12.1
    container_name: logstash
    command:
      - /bin/bash
      - -c
      - |
        cp /usr/share/logstash/pipeline/logstash.yml /usr/share/logstash/config/logstash.yml
        echo "Waiting for Elasticsearch availability";
        until curl -s http://elasticsearch:9200 | grep -q "missing authentication credentials"; do sleep 1; done;
        echo "Starting logstash";
        /usr/share/logstash/bin/logstash -f /usr/share/logstash/pipeline/logstash.conf
    environment:
      - xpack.monitoring.enabled=false
      - ELASTIC_USER=elastic
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - ELASTIC_HOSTS=http://elasticsearch:9200
    volumes:
      - ./logstash.conf:/usr/share/logstash/pipeline/logstash.conf

```

---

<div class="post-metadata">

**Author:** ![Musab\_Dogan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/musab_dogan/32/70691_2.png) [@Musab\_Dogan](https://discuss.elastic.co/u/Musab_Dogan)\
**Post date:** [August 12, 2024, 10:39am UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/3 "2024-08-12T10:39:07Z")

</div>

Add `network.host: 0.0.0.0` into `elasticsearch.environment`. If it not works, add `network` information into docker compose.

Ref:

> <https://stackoverflow.com/questions/31677563/elasticsearch-failed-to-connect-to-localhost-port-9200-connection-refused>

> **[Docker Networking](https://www.elastic.co/blog/docker-networking)**
>
> Learn about Docker networking and how to use it with an Elasticsearch cluster....

---

<div class="post-metadata">

**Author:** ![Edzel\_Severino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edzel_severino/32/136690_2.png) [@Edzel\_Severino](https://discuss.elastic.co/u/Edzel_Severino)\
**Post date:** [August 20, 2024, 4:35pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/4 "2024-08-20T16:35:45Z")

</div>

Its working now. Thank you Musab\_Dogan!

---

<div class="post-metadata">

**Author:** ![Musab\_Dogan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/musab_dogan/32/70691_2.png) [@Musab\_Dogan](https://discuss.elastic.co/u/Musab_Dogan)\
**Post date:** [August 21, 2024, 7:11am UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/5 "2024-08-21T07:11:36Z")

</div>

You're welcome @Edzel_Severino. Which method worked?

---

<div class="post-metadata">

**Author:** ![Edzel\_Severino](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/edzel_severino/32/136690_2.png) [@Edzel\_Severino](https://discuss.elastic.co/u/Edzel_Severino)\
**Post date:** [August 21, 2024, 5:08pm UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/6 "2024-08-21T17:08:47Z")

</div>

> [@Musab\_Dogan](#):
>
> network.host: 0.0.0.0

We add the network.host: 0.0.0.0 in Elasticsearch environment. However, instead of network.host: 0.0.0.0, what we did is network.host=0.0.0.0  
For some reasons, it works.

---

<div class="post-metadata">

**Author:** ![Musab\_Dogan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/musab_dogan/32/70691_2.png) [@Musab\_Dogan](https://discuss.elastic.co/u/Musab_Dogan)\
**Post date:** [August 25, 2024, 11:48am UTC](https://discuss.elastic.co/t/failed-to-connect-to-localhost-port-9200-connection-refused/364710/7 "2024-08-25T11:48:06Z")

</div>

It's because of the `docker-compose` syntax.

Thank for your feedback, and happy to hear it worked!
