Docker Community Forums

Share and learn in the Docker community.

How to delay execution of next line in Dockefile


(Quickdocker) #1

Hi,

I am new to docker.

I need ‘cqlsh’ to execute my build_all.cql. However, ‘cqlsh’ is not ready…it takes about 60 seconds for cqlsh to be ready. How do you do ‘wait’ with Dockerfile?

cat Dockerfile

FROM store/datastax/dse-server:5.1.8

USER root

RUN apt-get update
RUN apt-get install -y vim

ADD db-scripts-2.1.33.2-RFT-01.tar /docker/cms/
COPY entrypoint.sh /entrypoint.sh

WORKDIR /docker/cms/db-scripts-2.1.33.2/
RUN cqlsh -f build_all.cql

USER dse

=============

Output:

Step 8/9 : RUN cqlsh -f build_all.cql
—> Running in 08c8a854ebf4
Connection error: (‘Unable to connect to any servers’, {‘127.0.0.1’: error(111, “Tried connecting to [(‘127.0.0.1’, 9042)]. Last error: Connection refused”)})
The command ‘/bin/sh -c cqlsh -f build_all.cql’ returned a non-zero code: 1

Thank you.


(Todd W.) #2

In your last RUN statement, you can do something like:
RUN sleep 60;cqlsh -f build_all.cql


(Quickdocker) #3

Same issue. I tried with 60 seconds still same issue. Increased to 90 seconds same issue.
Is there a way to detect from Dockerfile if cqlsh is ready or not?

Step 16/17 : RUN sleep 90; cqlsh -f build_all.cql
—> Running in 99ca484df871
Connection error: (‘Unable to connect to any servers’, {‘127.0.0.1’: error(111, “Tried connecting to [(‘127.0.0.1’, 9042)]. Last error: Connection refused”)})
The command ‘/bin/sh -c sleep 90; cqlsh -f build_all.cql’ returned a non-zero code: 1


(Todd W.) #4

Are you exposing port 9042? That might be why you are getting connection refused.
Check https://docs.docker.com/engine/reference/builder/#expose for EXPOSE usage.


(David Maze) #5

If the command depends on connecting to a running daemon on localhost, it will never be “ready”, since every RUN command starts in a totally clean environment with no running processes.