5

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?

RonU
  • 5,525
  • 3
  • 16
  • 13
Appu
  • 185
  • 1
  • 3
  • 6

2 Answers2

4

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
RonU
  • 5,525
  • 3
  • 16
  • 13
jan-di
  • 755
  • 7
  • 16
2

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
Kemal Kaplan
  • 932
  • 8
  • 21