Wait node.js until Logstash is ready using containers

纵然是瞬间 提交于 2019-12-06 16:18:45

Docker compose does not wait until a container is ready, it will only wait until it's running.

depends_on will only ensure that logstash launches before your node container, but again, this doesn't mean it will wait until it is ready.

You can either handle the checks yourself on node, or use a wrapper script. In docker-compose documentation, they recommend, wait-for-it or dockerize

You can read more on this in here


Custom wrapper

Your node container command can change from node index.js (or whatever you have), to bash wait-for-logtash.sh:

#!/bin/bash

## Or whatever command is used for checking logstash availability
until curl 'http://logstash:5045' 2> /dev/null; do
  echo "Waiting for logtash..."
  sleep 1; 
done

# Start your server
node index.js
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!