Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send signal to program run in a docker container?

I have a program run in a docker container with detached mode.

So how to send a signal such as SIGINT to this program?

like image 449
atupal Avatar asked Sep 05 '14 13:09

atupal


People also ask

Does docker stop send sigint?

We know that docker stop sends a SIGTERM to the container process.

How do you display running processes inside a container?

Like it was mentioned, if you are already inside of a container, then just use ps -eaf command to see the running processes.


2 Answers

You can use docker kill --signal="<signal>" <container name or id> to send any signal to the root process of a given container.

See https://docs.docker.com/engine/reference/commandline/kill/#send-a-custom-signal--to-a-container

like image 104
Andy Avatar answered Sep 24 '22 23:09

Andy


You can use nsenter to get into your container space and send your signal.

PID=$(docker inspect --format {{.State.Pid}} <container_name_or_ID>) nsenter --target $PID --mount --uts --ipc --net --pid kill -SIGINT <PID of your program inside your container> 

More info : http://jpetazzo.github.io/2014/06/23/docker-ssh-considered-evil/

like image 37
Regan Avatar answered Sep 24 '22 23:09

Regan