5 ms·
I'd really-really need DNS for non-running containers, somehow. Nginx can't start if an upstream container is down, as its name won't be resolved.
by sz4kerto 11y ago
I'd really-really need DNS for non-running containers, somehow. Nginx can't start if an upstream container is down, as its name won't be resolved.
- bmelton 11y agoI'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 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 to its specification
- Myrmornis 11y agoJust in case a shorter version appeals to you, I think you could rewrite it like this: timeout 60 bash -c 'until is_ready; do sleep 10; done' You'll need to `export -f is_ready` if it's a shell function. That's assuming you can use a timeout instead of number-of-retries. http://man7.org/linux/man-pages/man1/timeout.1.html http://man7.org/linux/man-pages/man1/timeout.1.html
- bmelton 11y agoI was trying to find the source of where I got that bash script from, but couldn't, and then forgot about it within the editing window. I'll try to find it and provide that feedback. Thanks!
- baq 11y agowe've got consul set up in a way that points names to a known 503 service if its containers are not up.