Docker Community Forums

Share and learn in the Docker community.

Killing a docker run process and associated container

On centos, I’d like to execute the docker run command and then externally kill the process of the docker run command and its associated container.

Just to illustrate consider the following example:

timeout -s SIGKILL 5 docker run --rm ubuntu sleep 30

The docker run process is indeed externally killed in 5 seconds but the container continues to run until the sleep of 30 seconds completes. I’d like to kill both at the same time.

My actual problem is a bit more complicated - I’m running docker in a linux cluster. I submit a job to run docker and the job scheduler creates a process running docker. If I cancel the job, the job scheduler kills my docker process but the container is still running.

Here’s some info on docker and centos:
Server Version: 19.03.2
Kernel Version: 3.10.0-957.27.2.el7.x86_64
Operating System: CentOS Linux 7 (Core)
Architecture: x86_64

tia.

Why you wanted to do this? any specific reason.