Docker Community Forums

Share and learn in the Docker community.

Socker stack rm - SIGTERM not sent to the running process


(Aphasia0) #1


I need to execute a custom shutdown procedure for my containers. To handle this I’ve added a trap in the entry point script:

trap '' SIGTERM

This works very well if I use:

docker stop myContainerId

but, using swarm I’m not able to catch any signal from the container, so my stops will be never graceful.
I’ve tried:

docker stack rm myStackName
docker service rm myServiceName
docker service scale myServiceName=0

All the above commands kills my container with SIGKILL I think (waiting the default grace period of 10 seconds). It seems like swarm behind the scenes uses:

docker container rm -f myContainerId

My docker version:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)

EDIT2: I definitely found where the issue is. I receive the SIGTERM into the container but the shutdown procedure fails. The reason is that I cannot use neither ServiceName nor any alias. It seems like the overlay network is detached and then the signal is sent to the container.

Can you help me? Is this a bug or I’m doing something basically wrong?

Thank you.