Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Docker STOPSIGNAL do?

Tags:

I am trying to understand what exactly the STOPSIGNAL command in a dockerfile does. So according to the Docker Docs:

The STOPSIGNAL instruction sets the system call signal that will be sent to the container to exit. This signal can be a valid unsigned number that matches a position in the kernel’s syscall table, for instance 9, or a signal name in the format SIGNAME, for instance SIGKILL.

With this explanation I understand that there is some signal that is sent to the docker container to tell inside applications to stop. But when I shutdown a running container with sudo docker stop container-name, doesn't it then automatically also stops everything that runs inside? I can type this command without getting any errors. Isn't it then redundant to explicitly define STOPSIGNAL inside a dockerfile?

Looking at how Nginx is built with a dockerfile, the command STOPSIGNAL SIGTERM is used. But what does that exaclty mean? Would it break something to not define STOPSIGNAL?

like image 453
Socrates Avatar asked Jun 17 '18 15:06

Socrates


People also ask

Does docker stop delete data?

No, you won't lose any data when Docker container exits. Any data that your application writes to the container gets preserved on the disk until you explicitly delete the container. The file system for the container persists even after the container halts.

How do Dockerfiles work?

A Dockerfile is a text file of instructions which are used to automate installation and configuration of a Docker image. Dockerfiles make it easy to deploy multiple Docker containers without having to maintain the same image across multiple virtual machines.

What does Docker compose up D do?

The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f ). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running.

How do I remove all images from docker?

Remove all Containers: To remove all containers from the docker-machine, we need to get the ids of all the containers. We can simply get the ids of the containers with the command docker ps -aq, then by using the docker rm command, we can remove all the containers in the docker-machine.


1 Answers

SIGTERM is the default signal sent to containers to stop them: https://docs.docker.com/engine/reference/commandline/stop/

STOPSIGNAL does allow you to override the default signal sent to the container. Leaving it out of the Dockerfile causes no harm - it will remain the default of SIGTERM.

This being said, it is unclear why the author has explicitly defined the STOPSIGNAL as SIGTERM.

Looking at this commit, we can see that the STOPSIGNAL used to be set to SIGQUIT.

My guess is that they left it in explicitly for documentation's sake after making the change.

Discussion of the change here: https://github.com/nginxinc/docker-nginx/issues/167

like image 56
sp0gg Avatar answered Oct 11 '22 09:10

sp0gg