当前位置: 首页 > 知识库问答 >
问题:

httpoison无法在docker环境中从webapp访问elasticsearch

濮阳振海
2023-03-14

当试图使用webapp(使用Elixir/Ecto作为后端语言)、postgres数据库、elasticsearch和kibana创建一个项目时,使用以下docker-compose.yaml文件:

version: '3'
services:
  registry:
    restart: always
    image: registry:2
    ports:
      - 443:443
    volumes:
      - /path/data:/var/lib/registry
      - /path/certs:/registry/certs
      - /path/auth:/registry/auth
  webapp:
    build:
      context: ../../../
      dockerfile: config/docker/dev/Dockerfile-dev
    container_name: MyWebApp-dev
    image: 'localhost:443/123'
    environment:
      - ELASTICSEARCH_URL=http://localhost:9200
      - ELASTICSEARCH_HOST=localhost
    ports:
      - "4000:4000"
      - "3000:3000"
    depends_on:
      - db
      - elasticsearch
      - kibana
    networks:
      - esnet
  db:
    image: postgres:10
    container_name: db
    environment:
      - POSTGRES_USER=paul
      - POSTGRES_PASSWORD=SilviaZita1
      - POSTGRES_DB=snitch_dev
    networks:
      - esnet
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - esnet
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=elasticsearch
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet

  kibana:
    image: docker.elastic.co/kibana/kibana:7.0.1
    ports:
      - "5601:5601"
    container_name: kibana
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
      - ELASTICSEARCH_HOST=elasticsearch
    depends_on:
    - elasticsearch
    networks:
      - esnet

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:  

,

共有1个答案

方梓
2023-03-14

我认为,当您试图从WebApp访问ElasticSearch时,会出现此连接拒绝错误。

在容器内使用localhost是指容器本身。在docker-compose中,如果您想访问侦听特定端口的另一个服务,那么您必须像http:// : 那样为您的URL设置框架

在您的情况下:

使用下面的撰写文件:

version: '3'
services:
  registry:
    restart: always
    image: registry:2
    ports:
      - 443:443
    volumes:
      - /path/data:/var/lib/registry
      - /path/certs:/registry/certs
      - /path/auth:/registry/auth
  webapp:
    build:
      context: ../../../
      dockerfile: config/docker/dev/Dockerfile-dev
    container_name: MyWebApp-dev
    image: 'localhost:443/123'
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
      - ELASTICSEARCH_HOST=elasticsearch
    ports:
      - "4000:4000"
      - "3000:3000"
    depends_on:
      - db
      - elasticsearch
      - kibana
    networks:
      - esnet
  db:
    image: postgres:10
    container_name: db
    environment:
      - POSTGRES_USER=paul
      - POSTGRES_PASSWORD=SilviaZita1
      - POSTGRES_DB=snitch_dev
    networks:
      - esnet
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: elasticsearch
    environment:
      - node.name=elasticsearch
      - discovery.seed_hosts=es02
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata01:/usr/share/elasticsearch/data
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - esnet
  es02:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.0.1
    container_name: es02
    environment:
      - node.name=es02
      - discovery.seed_hosts=elasticsearch
      - cluster.initial_master_nodes=elasticsearch,es02
      - cluster.name=docker-cluster
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    volumes:
      - esdata02:/usr/share/elasticsearch/data
    networks:
      - esnet

  kibana:
    image: docker.elastic.co/kibana/kibana:7.0.1
    ports:
      - "5601:5601"
    container_name: kibana
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200
      - ELASTICSEARCH_HOST=elasticsearch
    depends_on:
    - elasticsearch
    networks:
      - esnet

volumes:
  esdata01:
    driver: local
  esdata02:
    driver: local

networks:
  esnet:  
 类似资料:
  • 我在从 docker-compose.yml 文件(版本 -3.7)读取 .env 变量时遇到问题,这里首先我解释我的文件夹和示例代码结构 我的文件夹结构 my_app > src config.py app.py requirements.txt 其他文件 Dockerfile docker-compose.yml .包封/包围(动词envelop的简写) .env文件 这是我的示例 .env

  • 问题内容: 因此,我一直在寻找一个示例,说明如何从AWS EB Web界面为Docker容器指定环境变量。通常,在EB中,您可以添加运行时可用的环境属性。在切换到Docker之前,我曾在之前的部署中使用过这些工具,但是看来Docker对于如何处理环境属性有一些不同的规则,对吗?根据本文[1],环境变量中将仅包含AWS凭证和PARAM1-PARAM5,但不会显示任何自定义属性。这对我来说听起来像是,

  • 我可以对Docker API进行cUrl调用,但是如果我从容器(docker-comals)运行相同的脚本,我就无法到达任何API终结点。 我的请求如下: 原因可能是使用了localhost,但我现在还找不到解决方案。有什么建议吗? 编辑:下面是我正在使用的堆栈(Api平台)的简要摘要https://api-platform.com/).每个容器都连接到“api_默认”网桥网络: 基于php=Sy

  • https://github.com/confluentinc/cp-docker-images/blob/5.0.0-post/examples/kafka-cluster/docker-compose.yml 我已经编辑了该文件,并将选项添加到docker组合文件中,以便可以在主机之外访问它们。 我已经运行了以下命令: kafka-1、kafka-2、kafka-3的docker日志(均相同)

  • 我成功安装了Apache Tomcat9,并访问了servername:8080。 null

  • 我是docker的新手,正在尝试容器化一个简单的Spring Boot应用程序。docker文件如下所示。 谢谢!!