You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker中无法连接Cassandra实例,出现ConnectionRefusedError

Cassandra容器脚本连接失败问题

我通过Docker运行Cassandra容器,配置如下,尝试在Cassandra启动运行后执行script.sh脚本,但该脚本持续记录如下错误:

dd_cassandra  | Connection error: ('Unable to connect to any servers', {'127.0.0.1:9042': ConnectionRefusedError(111, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
dd_cassandra  | Waiting for cassandra-node-1...

我尝试了检查Cassandra节点就绪状态的方案,仅在Cassandra就绪后执行脚本,但脚本陷入无限等待。

配置文件

docker-compose.yml

version: '3'

services:
  dd_cassandra:
    container_name: dd_cassandra
    build:
      context: ./cassandra
      dockerfile: Dockerfile
      args:
        BASE_IMAGE: cassandra:latest
    ports:
      - "9042:9042"

cassandra/Dockerfile

ARG BASE_IMAGE
FROM ${BASE_IMAGE}

COPY script.sh /
RUN chmod +x /script.sh
EXPOSE 9042
CMD ["/script.sh"]

cassandra/script.sh

#!/bin/bash

while ! cqlsh -e 'describe cluster' ; do
  echo "Waiting for cassandra-node-1...";
  sleep 10
done

# some other piece of code that adds runs `cqlsh` command 
# in the cassandra database

内容的提问来源于stack exchange,提问作者asn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 03:03:11