Home > Software engineering >  Web container can't connect to the Elasticsearch container in Azure App Service (using docker-c
Web container can't connect to the Elasticsearch container in Azure App Service (using docker-c

Time:11-16

Error at indexing step:

elastic_transport.ConnectionError: Connection error caused by: ConnectionError(Connection error caused by: ProtocolError(('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))))

Docker-compose on Azure App service:

version: '3'

services:
  elasticsearch:
    image: "elasticsearch:8.2.2"
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      - xpack.security.enabled=false
      - bootstrap.memory_lock=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es_config:/usr/share/elasticsearch/config
    ports:
      - "9200:9200"
    networks: 
      - esnet

  web:
    image: web:latest
    ports:
      - "80:80"
    links:
      - elasticsearch
    depends_on:
      - elasticsearch
    environment:
      ELASTIC_HOST: ${ELASTIC_HOST}
    networks: 
      - esnet

volumes:
  es_config:
    driver: azure_file
    driver_opts:
      share_name: elasticsearch
      storage_account_name: storageaccount

networks:
  esnet:
    driver: bridge
ELASTIC_HOST=http://elasticsearch:9200
client = Elasticsearch(ELASTIC_HOST)

How to connect to ES?

CodePudding user response:

Tldr;

You need to put both services in the same network from them to be able to access one another.

Solution

ELASTIC_HOST=https://elasticsearch:9200 <- httpS
client = Elasticsearch(ELASTIC_HOST)
version: '3'

services:
  elasticsearch:
    image: "elasticsearch:8.2.2"
    container_name: elasticsearch
    environment:
      - discovery.type=single-node
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      - xpack.security.enabled=false
      - bootstrap.memory_lock=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - es_config:/usr/share/elasticsearch/config
    ports:
      - "9200:9200"
    networks: 
      - esnet

web:
  image: web:latest
  ports:
    - "80:80"
  links:
    - elasticsearch
  depends_on:
    - elasticsearch
  environment:
    ELASTIC_HOST: ${ELASTIC_HOST}
    networks:  // <- This part needs to be added.
      - esnet

volumes:
  es_config:
    driver: azure_file
    driver_opts:
      share_name: elasticsearch
      storage_account_name: storageaccount

networks:
  esnet:
    driver: bridge

CodePudding user response:

Which Security configs did you turned off?

  • Related