Graylog2 / graylog-docker

Official Graylog Docker image
https://hub.docker.com/r/graylog/graylog/
Apache License 2.0
361 stars 133 forks source link

Graylog should wait for elasticsearch server #149

Closed bendavis78 closed 3 years ago

bendavis78 commented 3 years ago

Using the docker-compose examples from the documentation results in Graylog not being able to connect to elasticsearch, because elasticsearch sometimes takes a bit longer to start up.

The graylog entrypoint script should wait for the elasticsearch server before starting Graylog, otherwise the container will fail and exit.

As a workaround, I've resorted to using sleep in my docker-compose to give elasticsearch more time to start up:

    entrypoint:
      - /bin/sh
      - -c
      - |
        sleep 30;
        /docker-entrypoint.sh

Note that depends_on is not enough to guarantee that the server is accepting connections. According to Docker docs, depends_on only determines the order in which containers are started. It waits until the container is running before starting the next, but that does not mean that the elasticsearch server is accepting connections yet.

malcyon commented 3 years ago

Yes, I ran into this, too. I'm adding the wait-for-it script onto the image to allow for it to be used to handle this.

malcyon commented 3 years ago

The wait-for-it script is in the 4.0.2 image now. So you can set your entrypoint like this:

entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh

And it will wait for Elasticsearch to start up before starting Graylog.