Docker Compose健康检查遗留大量curl僵尸进程问题问询
Docker Compose:数百个健康检查进程未终止
健康检查配置
services: tomcat: ... healthcheck: test: - CMD-SHELL - curl --fail http://localhost:8080 || exit 1 interval: 5s timeout: 5s retries: 30
进程查询结果
执行命令:ps aux | grep curl
tomcat 939765 0.0 0.0 0 0 ? Z 08:46 0:00 [curl] <defunct> tomcat 939824 0.0 0.0 0 0 ? Z 08:46 0:00 [curl] <defunct> tomcat 939904 0.0 0.0 0 0 ? Z 08:47 0:00 [curl] <defunct> tomcat 939962 0.0 0.0 0 0 ? Z 08:47 0:00 [curl] <defunct> tomcat 940038 0.0 0.0 0 0 ? Z 08:47 0:00 [curl] <defunct> tomcat 940094 0.0 0.0 0 0 ? Z 08:47 0:00 [curl] <defunct> tomcat 940321 0.0 0.0 0 0 ? Z 08:48 0:00 [curl] <defunct> tomcat 940380 0.0 0.0 0 0 ? Z 08:48 0:00 [curl] <defunct> tomcat 940460 0.0 0.0 0 0 ? Z 08:48 0:00 [curl] <defunct> tomcat 940516 0.0 0.0 0 0 ? Z 08:48 0:00 [curl] <defunct> tomcat 940600 0.0 0.0 0 0 ? Z 08:49 0:00 [curl] <defunct> tomcat 940657 0.0 0.0 0 0 ? Z 08:49 0:00 [curl] <defunct> tomcat 940734 0.0 0.0 0 0 ? Z 08:49 0:00 [curl] <defunct> tomcat 940875 0.0 0.0 0 0 ? Z 08:49 0:00 [curl] <defunct> tomcat 940955 0.0 0.0 0 0 ? Z 08:50 0:00 [curl] <defunct> tomcat 941013 0.0 0.0 0 0 ? Z 08:50 0:00 [curl] <defunct> tomcat 941102 0.0 0.0 0 0 ? Z 08:50 0:00 [curl] <defunct> tomcat 941162 0.0 0.0 0 0 ? Z 08:50 0:00 [curl] <defunct> tomcat 941244 0.0 0.0 0 0 ? Z 08:51 0:00 [curl] <defunct> tomcat 941332 0.0 0.0 0 0 ? Z 08:51 0:00 [curl] <defunct> tomcat 941392 0.0 0.0 0 0 ? Z 08:51 0:00 [curl] <defunct> tomcat 941474 0.0 0.0 0 0 ? Z 08:51 0:00 [curl] <defunct> tomcat 941532 0.0 0.0 0 0 ? Z 08:52 0:00 [curl] <defunct> tomcat 941609 0.0 0.0 0 0 ? Z 08:52 0:00 [curl] <defunct> tomcat 941671 0.0 0.0 0 0 ? Z 08:52 0:00 [curl] <defunct> tomcat 941749 0.0 0.0 0 0 ? Z 08:52 0:00 [curl] <defunct> tomcat 941810 0.0 0.0 0 0 ? Z 08:53 0:00 [curl] <defunct> .... tomcat 941895 0.0 0.2 22364 8436 ? S 08:53 0:00 curl --fail http://localhost:8080 tomcat 941954 0.0 0.2 22364 8512 ? S 08:53 0:00 curl --fail http://localhost:8080 tomcat 942032 0.0 0.2 22364 8384 ? S 08:53 0:00 curl --fail http://localhost:8080 tomcat 942238 0.0 0.2 22364 8528 ? S 08:54 0:00 curl --fail http://localhost:8080 tomcat 942316 0.0 0.2 22364 8552 ? S 08:54 0:00 curl --fail http://localhost:8080 tomcat 942377 0.0 0.2 22364 8496 ? S 08:55 0:00 curl --fail http://localhost:8080 tomcat 942452 0.0 0.2 22364 8360 ? S 08:55 0:00 curl --fail http://localhost:8080 ...
问题解答
问题1:容器被判定为健康状态后,健康检查是否仍会定期执行?
是的,Docker的健康检查在容器进入健康状态后仍会按照配置的interval参数定期执行。这是默认设计,用于持续监控容器状态,一旦后续检查失败,容器会被标记为不健康。
问题2:导致curl进程无法终止(出现大量僵尸进程)的原因是什么?
出现大量<defunct>僵尸curl进程的核心原因是父进程未调用wait()系列系统调用回收子进程的退出状态,结合你的配置具体分析:
- 使用
CMD-SHELL模式时,Docker会启动一个shell进程(如sh)作为父进程,负责执行curl --fail http://localhost:8080 || exit 1命令 - curl执行完成退出后,shell父进程未正确回收其进程资源,导致curl进程成为僵尸进程(Z状态)
- 加上你设置的
interval为5秒,高频检查会快速积累大量未被回收的僵尸进程
另外,部分处于S状态的活跃curl进程,可能是因为timeout设置为5秒,curl请求超时或卡住,导致进程无法及时退出。
内容的提问来源于stack exchange,提问作者eastwater
相关产品推荐
相关产品推荐

