AnswerBun.com

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

Server Fault Asked by leedm777 on January 1, 2022

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.

2 Answers

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".

Answered by FeepingCreature on January 1, 2022

With the --signal option to docker kill?

docker kill --signal=SIGHUP <container>

Or with docker exec?

docker exec <container> killall -HUP nginx

Answered by Michael Hampton on January 1, 2022

Add your own answers!

Related Questions

Puppetserver unable to locate gems

1  Asked on November 4, 2021

   

Is it okay to drop DNS type AAAA queries

1  Asked on November 4, 2021 by noyb

   

Set YUM versionlock, but allow updating to specific versions

0  Asked on November 4, 2021 by yakatz

   

How are systemd/system overrides supposed to work?

1  Asked on November 4, 2021 by philolegein

     

OpenVPN with PAM with systemd and SELinux

1  Asked on November 4, 2021 by check

         

LDAP+SSL configuration with OpenSMTPD

1  Asked on November 4, 2021 by azmeuk

     

SVN, check out folders based on authz

1  Asked on November 4, 2021 by still-shi

 

CentOS command not found

1  Asked on November 4, 2021 by jonas-heinze

       

IPtables as a reverse proxy

1  Asked on November 4, 2021 by ie

   

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP