I'm running a cassandra container with the the help of docker. For the below set of configuration I'm trying to run the script.sh script which should run after cassandra is up and running. However, the below script keeps logging ConnectionRefusedError(111) error:
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...
I used the solution described in this SO Post to check further execute the script only if cassandra is ready but it runs into an infinite wait.
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
CMDfrom the basecassandraimage, so nothing is actually starting Cassandra. Usually you'd include something like this as a fragment in an entrypoint script in a client container, not the server proper.cassandra:latest. The script should run on top of that image, right?CMDthat's present in the base image's Dockerfile.Your script runs instead of the CMD from the base cassandra image- do you mean my script execution has overridded some process which would have started the cassandra in that container?