Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda