Skip to content

Error connecting to Elasticsearch." The Elasticsearch cluster is not reachable from python app in same docker network #127473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Vijaygawate opened this issue Apr 28, 2025 · 1 comment
Labels
>bug needs:triage Requires assignment of a team area label

Comments

@Vijaygawate
Copy link

Elasticsearch Version

8.17

Installed Plugins

No response

Java Version

bundled

OS Version

ubuntu

Problem Description

I am using docker compose to create elasticsearch docker container using below compose file

 elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.17.0
    container_name: elasticsearch
    ports:
      - 9200:9200
    environment:
      - node.name=elasticsearch
      - cluster.name=docker-cluster
      - discovery.type=single-node
      - ELASTIC_PASSWORD=test
      - bootstrap.memory_lock=true
      - xpack.security.enabled=true
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - xpack.license.self_generated.type=basic
      - ES_JAVA_OPTS=-Xmx2g
      #- node.max_local_storage_nodes=6
    ulimits:
      memlock:
        soft: -1
        hard: -1
    healthcheck:
      test: ["CMD-SHELL", "curl -s http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=500ms"]
      retries: 300
      interval: 1s
    volumes:
      #- ./elasticsearch.yml:/etc/elasticsearch/elasticsearch.yml
      -  ./es_data:/usr/share/elasticsearch/data

Now, within the same docker-compose file, I have another Python app that is connecting to this Elasticsearch, but while trying, it says, Error connecting to Elasticsearch." The Elasticsearch cluster is not reachable.

Below is the way I am using to connect to elasticsearch

# Initialize components
post_process = PostProcessing()
es_connect = ESConnector()
es_host = environ.get("ELASTIC_SEARCH_HOST")
print(es_host)
es_user = environ.get("ELASTIC_SEARCH_NAME")
print(es_user)
es_password = environ.get("ELASTIC_SEARCH_PASSWORD")
print(es_password)
es = es_connect.connect_elasticsearch(es_host, es_user, es_password)

but when I am doing
Telnet from another running container to the Elasticsearch container IP it is connecting to.

Am I using the old way of connecting to Elasticsearch, or what am I missing? I have tried with the Elasticsearch host and container IP as well but no luck

Steps to Reproduce

custom app

Logs (if relevant)

No response

@Vijaygawate Vijaygawate added >bug needs:triage Requires assignment of a team area label labels Apr 28, 2025
@Vijaygawate Vijaygawate changed the title Elastic search container connection issue with python app Error connecting to Elasticsearch." The Elasticsearch cluster is not reachable from python app in same docker network Apr 28, 2025
@DaveCTurner
Copy link
Contributor

Thanks very much for your interest in Elasticsearch.

This appears to be a user question, and we'd like to direct these kinds of things to the Elasticsearch forum. If you can stop by there, we'd appreciate it. This allows us to use GitHub for verified bug reports, feature requests, and pull requests.

There's an active community in the forum that should be able to help get an answer to your question. As such, I hope you don't mind that I close this.

@DaveCTurner DaveCTurner closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug needs:triage Requires assignment of a team area label
Projects
None yet
Development

No branches or pull requests

2 participants