如何将发行版 elasticsearch 服务连接到 docker compose 中定义的另一个服务

How to connect distro elasticsearch service to another service defined in docker compose

嗨,我想连接到我的应用程序中的 Elasticsearch,它在 docker-compose.yml 中与 ditsro elasticsearch 和 kibana

一起定义为“cog-app”服务

当我 运行 docker 文件时,我无法连接到 elasticsearch,你能告诉我如何将 elasticsearch 服务连接到应用程序服务吗

我在 cog-app 服务中定义了 elasticsearch,但我与 elasticsearch 连接失败

version: "3"
services:
  cog-app:
    image: app:2.0
    build:
      context: .
      dockerfile: ./Dockerfile
    stdin_open: true
    tty: true
    ports:
      - "7111:7111"
    environment:
      - LANG=C.UTF-8
      - LC_ALL=C.UTF-8
      - CONTAINER_NAME=app
    volumes:
      - /home/developer/app:/app

  odfe-node1:
    image: amazon/opendistro-for-elasticsearch:1.13.2
    container_name: odfe-node1
    environment:
      - cluster.name=odfe-cluster
      - node.name=odfe-node1
      - discovery.seed_hosts=odfe-node1,odfe-node2
      - cluster.initial_master_nodes=odfe-node1,odfe-node2
      - bootstrap.memory_lock=true # along with the memlock settings below, disables swapping
      - "ES_JAVA_OPTS=-Xms2g -Xmx2g" # minimum and maximum Java heap size, recommend setting both to 50% of system RAM
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536 # maximum number of open files for the Elasticsearch user, set to at least 65536 on modern systems
        hard: 65536
    volumes:
      - odfe-data1:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9600:9600 # required for Performance Analyzer
      
  odfe-node2:
    image: amazon/opendistro-for-elasticsearch:1.13.2
    container_name: odfe-node2
    environment:
      - cluster.name=odfe-cluster
      - node.name=odfe-node2
      - discovery.seed_hosts=odfe-node1,odfe-node2
      - cluster.initial_master_nodes=odfe-node1,odfe-node2
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms2g -Xmx2g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - odfe-data2:/usr/share/elasticsearch/data
    networks:
      - odfe-net
  kibana:
    image: amazon/opendistro-for-elasticsearch-kibana:1.13.2
    container_name: odfe-kibana
    ports:
      - 5601:5601
    expose:
      - "5601"
    environment:
      ELASTICSEARCH_URL: https://odfe-node1:9200
      ELASTICSEARCH_HOSTS: https://odfe-node1:9200
    networks:
      - odfe-net

volumes:
  odfe-data1:
  odfe-data2:

networks:
  odfe-net:
    

请告诉我两个服务如何相互通信

由于 elasticsearch 服务 运行 在另一个容器中,因此 localhost 无效。您应该使用 odfe-node1:9200 作为 url