Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Docker Check if DB is Running

entrypoint.sh contains various cqlsh commands that require Cassandra. Without something like script.sh, cqlsh commands fail because Cassandra doesn't have enough time to start. When I execute the following locally, everything appears to work properly. However, when I run via Docker, script.sh never finishes. In other words, $status never changes from 1 to 0.

Dockerfile

FROM cassandra
RUN apt-get update && apt-get install -y netcat
RUN mkdir /dir
ADD ./scripts /dir/scripts
RUN /bin/bash -c 'service cassandra start'
RUN /bin/bash -c '/dir/scripts/script.sh'
RUN /bin/bash -c '/dir/scripts/entrypoint.sh'

script.sh

#!/bin/bash

set -e
cmd="$@"

status=$(nc -z localhost 9042; echo $?)
echo $status

while [ $status != 0 ]
do
  sleep 3s
  status=$(nc -z localhost 9042; echo $?)
  echo $status
done

exec $cmd

Alternatively, I could do something like until cqlsh -e 'some code'; do .., as noted here for psql, but that doesn't appear to work for me. Wondering how best to approach the problem.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're misusing the RUN command in your Dockerfile. It's not for starting services, it's for making filesystem changes in your image. The reason $status doesn't update is because you can't start Cassandra via a RUN command.

You should add service cassandra start and /dir/scripts/entrypoint.sh to your script.sh file, and make that the CMD that's executed by default:

Dockerfile

CMD ['/bin/bash', '-c', '/dir/scripts/script.sh']

script.sh

#!/bin/bash

set -e
# NOTE: I removed your `cmd` processing in favor of invoking entrypoint.sh
# directly.

# Start Cassandra before waiting for it to boot.
service cassandra start

status=$(nc -z localhost 9042; echo $?)
echo $status

while [ $status != 0 ]
do
  sleep 3s
  status=$(nc -z localhost 9042; echo $?)
  echo $status
done

exec /bin/bash -c /dir/scripts/entrypoint.sh
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!