dockerdocker-healthcheck

Docker health check targeting anothern container?


I have a docker container service-1 that does not support curl or wget or ping. The container does start up a service which is available on localhost:8080 when ready.

As I cannot write a curl health check for this container (due missing command), I need a nother solution to know, when this container is ready.

My idea was to use another container in the same network, which implements a healthcheck like so:

curl --fail service-1:8080 || exit 1

Sadly this seems not work. Can I execute a health check on container A that relies on another container?


Solution

  • Finally I found this cheeky hack:

     test: |
            exec 3<>/dev/tcp/localhost/8080
            echo -e "GET /ready HTTP/1.1\nhost: localhost:8080\n" >&3
            timeout --preserve-status 1 cat <&3 | grep -m 1 status | grep -m 1 UP
            ERROR=$?
            exec 3<&-
            exec 3>&-
            exit $ERROR