无法将在Docker容器中运行的spring-boot应用程序连接到cassandra容器

时间:2019-10-18 05:53:32

标签: spring spring-boot docker spring-mvc docker-compose

我尝试从spring-boot容器ping到cassandra容器,它工作正常。但是在调高应用范围时,出现类似的错误。

  

NoHostAvailableException:所有尝试查询的主机均失败(尝试:   cassandra / 172.21.0.3:9042   (com.datastax.driver.core.exceptions.TransportException:   [cassandra / 172.21.0.3:9042]无法连接))

Error image

docker-compose.yml

version: "2"
services:
  zookeeper:
    image: confluentinc/cp-zookeeper:5.3.1
    hostname: zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    volumes:
      - ./create_topic.sh:/create_topics.sh

  broker:
    image: confluentinc/cp-enterprise-kafka:5.3.1
    hostname: broker
    container_name: broker
    depends_on:
      - zookeeper
    ports:
      - "29092:29092"
      - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092
      KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
      CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092
      CONFLUENT_METRICS_REPORTER_ZOOKEEPER_CONNECT: zookeeper:2181
      CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1
      CONFLUENT_METRICS_ENABLE: "true"
      CONFLUENT_SUPPORT_CUSTOMER_ID: "anonymous"

  control-center:
    image: confluentinc/cp-enterprise-control-center:5.3.1
    hostname: control-center
    container_name: control-center
    depends_on:
      - zookeeper
      - broker
    ports:
      - "9021:9021"
    environment:
      CONTROL_CENTER_BOOTSTRAP_SERVERS: "broker:29092"
      CONTROL_CENTER_ZOOKEEPER_CONNECT: "zookeeper:2181"
      CONTROL_CENTER_REPLICATION_FACTOR: 1
      CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1
      CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1
      CONFLUENT_METRICS_TOPIC_REPLICATION: 1
      PORT: 9021

  cassandra:
    image: ************/cassandra_goldendata_baseimage:1.0.0
    container_name: cassandra
    ports:
      - "9042:9042"


  item-service:
    image: item-service
    depends_on:
      - zookeeper
      - broker
      - cassandra
    container_name: item-servicecontainer
    ports:
      - "4545:8080"

0 个答案:

没有答案