0

I faced with the following issue:

the container is running with the following healthcheck config (test is in question)

    healthcheck:
      test: ["CMD-SHELL", "curl -s -X GET http://127.0.0.1:5000/actuator/health", "|", "grep 'UP'"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 10s

in runtime I see that only the first part of the healthcheck test command (curl -s -X GET http://127.0.0.1:5000/actuator/health) is considered. The endpoint answers with status: Down, but healthcheck is passed - "Status": "healthy":

docker inspect 1f074dc72c6d | grep -i -A 10 health
            "Health": {
                "Status": "healthy",
                "FailingStreak": 0,
                "Log": [
                    {
                        "Start": "2019-12-10T11:37:46.215783033Z",
                        "End": "2019-12-10T11:37:46.315844469Z",
                        "ExitCode": 0,
                        "Output": "{\"status\": \"DOWN\"}"
                    },
                    {
                        "Start": "2019-12-10T11:38:16.346253717Z",
--
            "Healthcheck": {
                "Test": [
                    "CMD-SHELL",
                    "curl -s -X GET http://127.0.0.1:5000/actuator/health",
                    "|",
                    "grep 'UP'"
                ],
                "Interval": 30000000000,
                "Timeout": 3000000000,
                "StartPeriod": 10000000000,
                "Retries": 3

1 Answers1

1

CMD-SHELL takes one argument, the string gets passed to a shell that handles parsing the string:

test: ["CMD-SHELL", "curl -s -X GET http://127.0.0.1:5000/actuator/health | grep 'UP'"]
BMitch
  • 231,797
  • 42
  • 475
  • 450
  • thanks, do you know if it something documented or even know the source of this code? – Vladimir Avdoshka Dec 18 '19 at 11:00
  • @VladimirAvdoshka the compose file syntax is documented here: https://docs.docker.com/compose/compose-file/#healthcheck – BMitch Dec 18 '19 at 14:21
  • yes @BMitch, but it says there `test must be either a string or a list. If it’s a list, the first item must be either NONE, CMD or CMD-SHELL.` That what confused me in the first place. So it seems it does not make any sense to use CMD-SHELL with arrays. I created a PR on documentation - https://github.com/docker/docker.github.io/pull/10058 – Vladimir Avdoshka Dec 18 '19 at 14:40
  • @VladimirAvdoshka I'm looking at: "If it’s a string, it’s equivalent to specifying CMD-SHELL followed by that string." I read it as CMD-SHELL takes a single string. The overall `test` field can be a list, but how many items are permitted in the list varies by type. If the above answers your question, please be sure to check the box to mark the question as resolved. – BMitch Dec 18 '19 at 14:45
  • I agree @BMitch. It became somewhat clear after the second read but still might be confusing. If CMD-SHELL can take only a single string and specifying just a string without `CMD-SHELL` is equivalent to specifying it with `CMD-SHELL` why one needs `CMD-SHELL` at all? – Vladimir Avdoshka Dec 18 '19 at 14:56