I've had that problem too, and found that you can implement a "wait" command.
If you're using Docker Compose, add this to your environment:
environment:
- WAIT_COMMAND=[ $(curl --write-out %{http_code} --silent --output /dev/null http://elastic:9200/_cat/health?h=st) = 200 ]
- WAIT_START_CMD=python /code/lytten/main.py
- WAIT_SLEEP=2
- WAIT_LOOPS=10
Then, create a 'wait' bash script in your app's source code that looks like this:
!/bin/bash
echo $WAIT_COMMAND
echo $WAIT_START_CMD
is_ready() {
eval "$WAIT_COMMAND"
}
# wait until is ready
i=0
while ! is_ready; do
i=`expr $i + 1`
if [ $i -ge $WAIT_LOOPS ]; then
echo "$(date) - still not ready, giving up"
exit 1
fi
echo "$(date) - waiting to be ready"
sleep 10
done
#start the script
exec $WAIT_START_CMD
Then, finally, for your nginx container, add:
command: sh /code/wait_to_start.sh
If you're using Docker Compose, add this to your environment: environment: - WAIT_COMMAND=[ $(curl --write-out %{http_code} --silent --output /dev/null http://elastic:9200/_cat/health?h=st) = 200 ] - WAIT_START_CMD=python /code/lytten/main.py - WAIT_SLEEP=2 - WAIT_LOOPS=10
Then, create a 'wait' bash script in your app's source code that looks like this: !/bin/bash echo $WAIT_COMMAND echo $WAIT_START_CMD
Then, finally, for your nginx container, add: command: sh /code/wait_to_start.shto its specification