大网数据广告活动
服务器运维问答

How to send a signal to a Docker container without affecting restart policy?

· 52CE 我爱测

TIL that docker kill means kill in the sense of "make it dead" , as opposed to the POSIX sense of "send a signal". We have several containers that we need to send a SIGHUP to in order to reload configuration, but this causes them…

问题原文

原帖链接 · leedm777 · CC BY-SA 4.0

TIL that docker kill means kill in the sense of "make it dead", as opposed to the POSIX sense of "send a signal".

We have several containers that we need to send a SIGHUP to in order to reload configuration, but this causes them to ignore their restart policy of "always", which isn't what we want.

What's the best way to send signals to these containers without affecting their ability to auto-restart?


To more clearly demonstrate the issue we're seeing, take the following example.

We have some container that has a restart policy set to always

$ docker inspect cloudwatch-exporter | jq .[].HostConfig.RestartPolicy
{
  "Name": "always",
  "MaximumRetryCount": 0
}

We reload the config at some point using docker kill:

$ docker kill --signal=SIGHUP cloudwatch-exporter
cloudwatch-exporter

Some time later, something happens that kills the process. To simulate this, I'll send a signal within the container:

$ docker exec cloudwatch-exporter bash -c "kill 1"

At this point, the container is dead and won't restart:

$ docker ps -a | grep cloudwatch-exporter
c7827204bba5        prom/cloudwatch-exporter:cloudwatch_exporter-0.8.0                                "java -jar /cloudwat…"   20 hours ago        Exited (143) 3 minutes ago                            cloudwatch-exporter

What alternatives do we have for using docker kill? For many cases docker exec works, but it won't work for any container that only contains a single static-linked binary.

社区高分解答

原帖链接 · FeepingCreature · CC BY-SA 4.0

This is a known Docker bug.

See https://github.com/moby/moby/issues/11065 "Non-fatal signals break restart policies"

See https://github.com/moby/moby/issues/41302 "Signal breaks unless-stopped restart policy"

Bypass the problem by doing docker exec "kill -HUP 1".

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-07-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。