This article said that I was happy that Nginx's official Docker Image ** defaulted to graceful shutdown when the container shut down **. (1.19.5 or later)
We hope that the following people will be able to feel the joy as much as possible.
According to the wiki, "The program detects a serious error and terminates normally with some control." If you limit the web service to a container, you will have the following requirements.
Previously (v1.19.4 and below) when exiting an Nginx container, a SIGTERM signal
was sent. (It can be seen by setting the error log level of Nginx to notice or lower. The following log is for v1.19.3)
This is because the default behavior of docker and Kubernetes is to send a SIGTERM signal
when the container is closed.
See also: docker stop, docker-compose, Kubernetes
The problem is that ** when Nginx receives the SIGTERM signal
, it immediately transitions to shutdown behavior **. (From Nginx Official)
Therefore, if you operate with the default settings, a 502 error may occur in some cases.
To avoid this phenomenon, ** send a SIGQUIT signal
to the Nginx container **. (From Nginx Official)
The typical method is as follows.
It's a little bit, but in both cases, I felt that "I didn't know that!" Or "It's a hassle to process ...".
You don't have to do anything.
Images of Nginx 1.19.5 and above will override the STIOPSIGNAL
definition above and will send a SIGQUIT signal
by default. (The following is for v1.19.5)
This makes it unlikely that you'll have to mess with Dockerfile or define a preStop for graceful shutdown!
I'm a little happy.
If graceful shutdown is a requirement service using an Nginx container, v1.19.5 or higher may be a bit easier. However, please note that depending on the configuration and tools, graceful shutdown of Nginx alone may not meet the requirements.
Recommended Posts