Multiple health check curls in docker health check
Asked Answered
A

2

7

In order to ensure the health check of my container, I need to perform test calls to multiple URLS.

curl -f http://example.com and curl -f http://example2.com

Is it possible to perform multiple curl calls for a docker health check?

Ahrendt answered 25/7, 2021 at 16:35 Comment(0)
F
5

You can set a script as the healthcheck command that contains a more complex logic to perform the healthcheck. That way you can do multiple requests via curl and let the script only return positive if all requests succeeded.

# example dockerfile
COPY files/healthcheck.sh /healthcheck.sh
RUN chmod +x /healthcheck.sh
HEALTHCHECK --interval=60s --timeout=10s --start-period=10s \  
    CMD /healthcheck.sh
Forthwith answered 1/9, 2021 at 21:51 Comment(0)
I
3

Although I cannot test, I think you can use the following

HEALTHCHECK CMD (curl --fail http://example.com && curl --fail http://example2.com) || exit 1

If you want first to check this command manually (without exit part), you can check the last error code by

echo $? -> in linux

and

echo %errorlevel% -> in windows
Ichthyolite answered 25/7, 2021 at 17:31 Comment(1)
Thanks for the reply. I tried it but it only calls the first URL.Ahrendt

© 2022 - 2024 — McMap. All rights reserved.