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,
Python Garbage collection and memory leak hive Summary of processing methods for a large number of small files The difference between memory overflow and memory leak , Causes and Solutions Create data mysql Library process You don't know ——HarmonyOS stay Vue Use in Web WorkerSparkSQL Achieve partition overlay write msf Generate Trojan horse attack android mobile phone Linux Page replacement algorithm C Language implementation Django Personal blog building tutorial --- Time classified archiving