Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

signals

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

like image 602
pierrelb Avatar asked Jun 11 '15 08:06

pierrelb


People also ask

How do I transfer data from one container to another container?

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.

Can 2 Docker containers talk to each other?

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.


2 Answers

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
like image 182
pierrelb Avatar answered Oct 07 '22 02:10

pierrelb


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.

like image 34
Evgeny Chernyavskiy Avatar answered Oct 07 '22 02:10

Evgeny Chernyavskiy