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 to another one. So, how could I execute this command from another running container. Or is there another way of send a signal ?
Thanks in advance
Another way to copy files to and from Docker containers is to use a volume mount. This means we make a directory from the host system available inside the container. The command above runs a grafana container and mounts the /tmp directory from the host machine as a new directory inside the container named /transfer.
If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.
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
To accomplish this you'd want to mount Docker socket from host machine into the container you'd like to be sending signals from. See, for instance, this post for explanation and details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With