Home > Net >  Unable to connect to Elasticsearch using images in Docker-Compose
Unable to connect to Elasticsearch using images in Docker-Compose

Time:04-28

I can't connect my project to ElasticSearch when I run it from Docker Compose. ElasticSearch cannot read the logs, but when I run it locally it works normally.

docker-compose: version: '3.9'

services:

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    ports:
      - "9200:9200"
    networks:
      - network-elastic
    environment:
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"

  clinicaonline:
    build: .
    ports:
      - "5005:80"
    depends_on:
      - elasticsearch

networks: 
  network-elastic:
    driver: bridge

Connection string:

"Elasticsearch": {
    "Uri": "http://elasticsearch:9200"
  }

CodePudding user response:

You need to add same the network(network-elastic) to the clinicaonline service. This should work:

services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.11.1
    ports:
      - "9200:9200"
    networks:
      - network-elastic
    environment:
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xms1g -Xmx1g"
  clinicaonline:
    build: .
    ports:
      - "5005:80"
    networks:
      - network-elastic
    depends_on:
      - elasticsearch
networks: 
  network-elastic:
    driver: bridge
  • Related