Issue
I would like to do something like this in a Dockerfile for windows:
HEALTHCHECK --interval=5s \
--timeout=5s \
CMD C:\\src\\curl.exe -f http://127.0.0.1:8080/health; if($LastExitCode) {$LastExitCode=1}
The command itself seems to be fine. Exit code is changed to 1 whenever curl returns something different than 0. The problem appears when I try to define it in a Dockerfile. When Docker runs it I got following output in inspect:
(6) Couldn't resolve host 'if($LastExitCode)'\r\ncurl: (6) Couldn't resolve host '$LastExitCode=1'\r\n"
So basically he treats everything after semicolon as an argument of curl. Any idea how can I tackle this? I know I can write a script and put it inside container, but I'd rather not do that.
Solution
Finally solved it! In case someone else needs, here is a solution that worked for me:
CMD powershell C:\\src\\curl.exe -f http://127.0.0.1:8080/health; if($LastExitCode) {exit 1}
Answered By - Piotr Tempes