Can't connect to ElasticSearch from python API in Docker-Compose setup

Here is how I create the ES container in Docker-Compose:

    restart: always
      - 9200:9200
      - 9300:9300
        soft: -1
        hard: -1
      discovery.type: single-node db

Here is how I'm attempting to connect from the Python API:

from elasticsearch import Elasticsearch
es = Elasticsearch(
    {'host': 'db', 'port': 9200, 'use_ssl': False},

localhost:9200 works fine when the container is running, but the connection does not work. Whenever I dont set the ENV the error I get is

Errno -2: Name or Service not known

And when I do set the ENV the error is

Errno -5: No address associated with this host name

Any help or advice would be very, very appreciated. Thank you!

Welcome to our community! :smiley:

Try setting to

Thanks for the warm welcome warkolm! I did try that previously and unfortunately it gave me the same error as it does with the hostname set to db.

Where did you set that and what was the error?

I set it in the same place I set " db" and the error was
"No address associated with this host name"

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