How does docker scale work

I would like to use Python to receive the Docker stop signal for other processing, but I have no idea how the Docker scale command reduces replication, stop or kill?

Since this post has the swarm tag, I will concentrate on swarm services. When the replication scale of a service is updated, the desired state is set and the scheduler will detect a missmatch between the desired and current state. As a result the scheduler will identify that actual - desired tasks need to be terminat. To terminate a task, it will send a stop signal - if the container does not terminate within the grace period, it will kill the container, the same way like it happens with plain containers as well.

Of course your Python app will only receive the signal, if it runns as PID1.

1 Like

thanks for your advice,i also use docker engine to replace docker swarm to test,i discovery it will post stop signal first,after about 10 seconds it will post kill signal,this discovery give me the confidence to complete my task