英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论