How to stop running docker Container and terminate the program correctly , This has become a topic worthy of discussion . in fact , In our daily projects , This is a problem that we often have to face and deal with :

scene A: If we package the program in a container , provide HTTP Mode of service , Responsible for handling all kinds of HTTP
requests And return the result , We must hope that when the container is stopped , It allows the program time to continue processing the request that is already in process , And return the result to the client .


scene B: Another example is our program packaged in a container , Responsible for writing data to a data file , We want the program to work when the container is stopped , There is time to persist the data cached in memory to the storage device , In case of data loss .


scene C: Another example is the popular microservice architecture , Generally, there will be a service discovery mechanism , That is, after each microservice is started , They will actively register their address information into the service discovery module , Let other services know their existence . And when the container is stopped , Microservices need to log off from the service discovery module immediately , To prevent API
Gateway The incoming request was misrouted to the stopped microservice .

In the various scenarios above , Both require applications packaged in containers to be terminated gracefully ( That is to say gracefully shutdown), such gracefully
shutdown The way , Allow the program to stop when the container is stopped , Have some time to do some subsequent processing operations .

docker stop

When we use docker stop When you order to stop the container ,docker By default, applications in the container are allowed to have 10 Seconds to terminate the operation . So we look at it docker
stop When ordering help , There will be the following tips :
→ docker stop --help Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]
Stop one or more running containers Options: --help Print usage -t, --time int S

©2019-2020 Toolsou All rights reserved,
Send love - A little romance for programmers VHDL—— Design of frequency divider Python Implementation of Hanoi Tower code It's over , Starting salary 30khtml+css+js Make a simple website home page QQ Login interface implementation Hill sorting of sorting algorithm ——c++ realization 【 Wechat applet learning 】 Netease music cloud code page implementation details Resume the 13th session python Blue Bridge Cup 2022 Solution to the 13th Blue Bridge Cup ( whole )