I have a python script as a "service manager" to run multiple docker containers. I already handled graceful shutdown (cltr+c). However when I pkill -9
the python script, the dockers are still running.
libc = ctypes.CDLL("libc.so.6")
def set_pdeathsig(sig=signal.SIGTERM):
def callback():
return libc.prctl(1, sig)
return callback
open_container_cmd = "docker-compose run --rm -d test"
proc = subprocess.Popen(
open_container_cmd,
shell=True,
stdout=open(os.devnull, 'wb'),
preexec_fn=set_pdeathsig(signal.SIGTERM))
I followed this answer but no luck. I even tried executing in terminal kill -9 pid
to kill docker container with process ID from proc = subprocess.Popen(open_container_cmd); proc.pid
but it won't even stop the container.