Docker daemon always stops healthcheck before sending signal to a
container now. However, when we use "docker kill" to send signals
other than SIGTERM or SIGKILL to a container, such as SIGINT,
daemon still stops container health check though container process
handles the signal normally and continues to work.
Signed-off-by: Ruilin Li <liruilin4@huawei.com>
(cherry picked from commit da574f93432e600fda561da5e6983e7f69b364a9)
Signed-off-by: Dani Louca <dani.louca@docker.com>
| ... | ... |
@@ -165,3 +165,29 @@ ENTRYPOINT /bin/sh -c "sleep 600"`)) |
| 165 | 165 |
waitForHealthStatus(c, name, "starting", "healthy") |
| 166 | 166 |
|
| 167 | 167 |
} |
| 168 |
+ |
|
| 169 |
+// GitHub #37263 |
|
| 170 |
+func (s *DockerSuite) TestHealthKillContainer(c *check.C) {
|
|
| 171 |
+ testRequires(c, DaemonIsLinux) // busybox doesn't work on Windows |
|
| 172 |
+ |
|
| 173 |
+ imageName := "testhealth" |
|
| 174 |
+ buildImageSuccessfully(c, imageName, build.WithDockerfile(`FROM busybox |
|
| 175 |
+HEALTHCHECK --interval=1s --timeout=5s --retries=5 CMD /bin/sh -c "sleep 1" |
|
| 176 |
+ENTRYPOINT /bin/sh -c "sleep 600"`)) |
|
| 177 |
+ |
|
| 178 |
+ name := "test_health_kill" |
|
| 179 |
+ dockerCmd(c, "run", "-d", "--name", name, imageName) |
|
| 180 |
+ defer func() {
|
|
| 181 |
+ dockerCmd(c, "rm", "-f", name) |
|
| 182 |
+ dockerCmd(c, "rmi", imageName) |
|
| 183 |
+ }() |
|
| 184 |
+ |
|
| 185 |
+ // Start |
|
| 186 |
+ dockerCmd(c, "start", name) |
|
| 187 |
+ waitForHealthStatus(c, name, "starting", "healthy") |
|
| 188 |
+ |
|
| 189 |
+ dockerCmd(c, "kill", "-s", "SIGINT", name) |
|
| 190 |
+ out, _ := dockerCmd(c, "inspect", "--format={{.State.Health.Status}}", name)
|
|
| 191 |
+ c.Check(out, checker.Equals, "healthy\n") |
|
| 192 |
+ |
|
| 193 |
+} |