diff --git a/Dockerfile b/Dockerfile index 2393756..56f4421 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,8 @@ WORKDIR /opt/zookeeper # Only checks if server is up and listening, not quorum. # See https://zookeeper.apache.org/doc/r3.5.5/zookeeperAdmin.html#sc_zkCommands -HEALTHCHECK CMD [ $(echo ruok | nc 127.0.0.1:2181) == "imok" ] || exit 1 +COPY healthcheck /healthcheck +HEALTHCHECK CMD /healthcheck VOLUME ["/opt/zookeeper/conf", "/tmp/zookeeper"] diff --git a/healthcheck b/healthcheck new file mode 100755 index 0000000..4680d77 --- /dev/null +++ b/healthcheck @@ -0,0 +1,11 @@ +#!/bin/bash +# Read bound host and port from the config file (if any) +set -e + +CFG=/opt/zookeeper/conf/zoo.cfg +if [ -e "$CFG" ]; then + H="$(awk -F= '/^clientPortAddress=/{ print $2 }' "$CFG")" + P="$(awk -F= '/^clientPort=/{ print $2 }' "$CFG")" +fi + +[ "$(echo ruok | nc "${H:-127.0.0.1}" "${P:-2181}")" == "imok" ] || exit 1