Docker HEALTHCHECK CMD即使使用”exit 0″也不会返回成功。

huangapple go评论47阅读模式
英文:

Docker HEALTHCHECK CMD won't return success even with "exit 0"

问题

问题就在标题上。我正在尝试设置健康检查,但无论我在参数数组中放什么,HEALTHCHECK 都会失败。

[ "exit 0"], [ "CMD", "exit 0" ], [ "CMD-SHELL", "exit 0" ],什么都不管用。

容器始终标记为不健康

这是我在 Dockerfile 中的完整命令。

HEALTHCHECK --interval=30s --timeout=10s --start-period=1m --retries=3 CMD [ "CMD-SHELL", "/healthcheck.sh" ]

我确认在容器上运行以下命令返回 0

> /healthcheck.sh && echo $? > 0

这产生了相同的结果,尽管这并不重要。

> /bin/sh /healthcheck.sh && echo $? > 0

我的 /healcheck.sh 脚本非常简单。

#!/bin/sh

tile38-cli HEALTHZ | grep -q true

RESULT=$?

echo "health check exited with status $RESULT"

exit $RESULT

怎么回事?

英文:

The question is in the title. I am attempting to setup health checks but the HEALTCHECK is always failing no matter what i put in for the args array.

[ "exit 0"], [ "CMD", "exit 0" ], [ "CMD-SHELL", "exit 0" ], nothing works.

The container is always marked as unhealthy.

Here is my full command from the Dockerfile.

HEALTHCHECK --interval=30s --timeout=10s --start-period=1m --retries=3 CMD [ "CMD-SHELL", "/healthcheck.sh" ]

I've confirmed running a the folowing on the container returns 0.

> /healthcheck.sh && echo $?
> 0

This has the same result, not that it matters.

> /bin/sh /healthcheck.sh && echo $?
> 0

My /healcheck.sh script is dead simple.

#!/bin/sh

tile38-cli HEALTHZ | grep -q true

RESULT=$?

echo "health check exited with status $RESULT"

exit $RESULT

What gives?

答案1

得分: 0

当我使用[]来指定命令时,原来它使用默认的SHELL,在Linux上是/bin/sh -c。这意味着它试图将我的脚本作为原始命令执行,而不是作为脚本。

解决方案是移除[]

HEALTHCHECK CMD /app/healthcheck.sh || exit 1
英文:

Turns out, when i specify the command with [] that specifies that it uses the default SHELL which on Linux is /bin/sh -c. This means its trying to execute my script as a raw command, not a script.

The solution is to remove the [].

HEALTHCHECK CMD /app/healthcheck.sh || exit 1

huangapple
  • 本文由 发表于 2023年6月13日 13:09:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76461843.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定