Here is how I create the ES container in Docker-Compose:
db:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.1
restart: always
ports:
- 9200:9200
- 9300:9300
ulimits:
memlock:
soft: -1
hard: -1
environment:
discovery.type: single-node
network.host: 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 network.host 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!