I have a docker compose file with a cassandra container. As default, I can manage the database anonymously because of AllowAllAuthenticator in cassandra.yaml, I want to have PasswordAuthenticator. That’s my docker compose:
cassandra:
image: cassandra:4.1
container_name: "cassdb"
ports:
- 9042:9042
volumes:
- ./cassandra:/var/lib/cassandra
environment:
- CASSANDRA_CLUSTER_NAME=cassclus
I tried copying the file outside the container, editing it and sending it back and restarting container.
I have also tried to copy it outside the container, editing it and creating a volume with it in order to load it on docker compose up:
- ./cassandra.yaml:/etc/cassandra/cassandra.yaml
In both cases, I get that error whenever doing cqlsh or cqlsh -u cassandra -p cassandra from inside the container (which I didn’t have before):
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")})
I have even tried to add the container with the volume but doing no change to the .yaml I have imported from the container, so I don’t think it is related with the PasswordAuthenticator value itself, but with the whole file.
My host machine is a Windows and I am editing the file with Visual Studio Code, I don’t know if that may have anything to do.
2
Answers
SOLVED: I wasn't patient enough, works fine but just needed a few minutes to the rebuild the entire container environment.
This issue keeps coming up so I’m posting here for those that come across this in the future.
The connection error returned by cqlsh is almost always one of two things:
In this case, it’s point (1) because the operator did not wait long enough for the Cassandra instance to come up.
A note to operators: reviewing the Cassandra logs should be your first step when troubleshooting an issue. Even when deployed in a Docker container, Cassandra still needs to go through its startup sequence and it is not instantaneous. Cheers!