For demonstration purposes, I would like to kill the process with PID 1 from inside a container. But apparently, kill 1 doesn't work:

$ sudo docker run -it centos
[root@3752d3a44f10 /]# ps
  PID TTY          TIME CMD
    1 pts/0    00:00:00 bash
   15 pts/0    00:00:00 ps
[root@3752d3a44f10 /]# kill 1
[root@3752d3a44f10 /]# kill -9 1
[root@3752d3a44f10 /]# kill -SEGV 1
[root@3752d3a44f10 /]# <-- shell is still running

Is there a way to explicitly kill the process with PID 1 from inside a container? How?

2 Answers 2


PID 1 is a special PID which will ignore certain signals unless handlers are explicitly created. Docker has some documentation on this:

Note: A process running as PID 1 inside a container is treated specially by Linux: it ignores any signal with the default action. So, the process will not terminate on SIGINT or SIGTERM unless it is coded to do so.

From here: https://docs.docker.com/engine/reference/run/#foreground

To kill PID 1 you will have to explicitly declare the handler for the SIGTERM signal or, in current versions of Docker, pass the --init flag in the docker run command to instrument tini.

  • Thank you very much @edaemon, especially for having mentioned the --init flag I wasn't aware of! Commented Dec 6, 2018 at 16:30

Also have this problem, solving by use follwing docker-entrypoint.sh

set -e
trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT SIGHUP

some_app &

You can 'kill 1' somewhere to exit this whole container.

  • What does it help to run it the background and then wait on it? Why not just run it?
    – chicks
    Commented Jul 3, 2021 at 2:56
  • amazing! this is the only solution that works
    – Alex
    Commented Mar 28, 2023 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.