无法连接我的springboot docker和我的cassandra docker

zed5wv10  于 2021-06-13  发布在  Cassandra
关注(0)|答案(1)|浏览(248)

我有一些问题,以dockerize我的 Spring 启动Cassandra应用程序。当我使用idea运行我的项目时,它可以正常工作,但当我将应用程序转换为docker容器时,我遇到了以下问题:“retryingcassandraclusterfactorybean:所有尝试查询的主机都失败(尝试:localhost/127.0.0.1:9042(com.datastax.driver.core.exceptions.transportexception:[localhost/127.0.0.1:9042]cannot connect))”

my application.properties: 
spring.data.cassandra.keyspace-name=keyspace
spring.data.cassandra.contact-points=127.0.0.1
spring.data.cassandra.port=9042
spring.data.cassandra.schema-action=create_if_not_exists
server.port=8081    

my cassandra :
cassandradb:
    image: "cassandra:latest"
    container_name: "cassandradb"
    ports:
      - "9042:9042"
      - "7191:7191"
      - "7001:7001"
      - "9160:9160"
      - "7000:7000"
    environment:
      CASSANDRA_CLUSTER: "myCluster"
      CASSANDRA_ENDPOINT_SNITCH: "GossipingPropertyFileSnitch"
      CASSANDRA_DC: "data"
      CASSANDRA_LISTEN_ADDRESS: "auto"

  photos:
    image: "photos:latest"
    container_name: "photo"
    ports:
      - "8081:8081"
    links:
      - "cassandradb"
4dc9hkyq

4dc9hkyq1#

错误发生了,因为你的Spring可以 t reach cassandradb. You should connect or via host ip, or use cassandradb`host,anc configure docker-compose.yml链接部分

相关问题