dockersignals

Docker: how to send a signal from one running container to another one?


I'm using docker, and I would like to know: Is it possible to send a signal, from a running container to another running container ?

More precisely, I would like to send SIGUSR1 to python program.

I already made a bash script to get pid of my python process and send the signal:

send_signal.sh

#!/bin/bash py_pid=$(pidof -s python my_programme.py kill -SIGUSR1 $py_pid

Before, I executed send_signal.sh from Docker host like that:

docker exec docker_with_python bash send_signal.sh

Or simply like that:

docker kill --signal="SIGUSR1 docker_with_python

But now, I would like to send signal to a running container from another one. So, how could I execute this command from another running container. Or is there another way to send a signal ?

Thanks in advance


Solution

  • This is the code I used. It could help someone else:

    echo -e "POST /containers/<docker_id>/kill?signal=SIGUSR1 HTTP/1.0\r\n" | nc -U /tmp/docker.sock
    

    Previously, in my docker-compose.yml, I shared volumes:

    example1:
       hostname: example_1
       volumes:
         - /var/run/docker.sock:/tmp/docker.sock