How to kill process inside container? Docker top command

我怕爱的太早我们不能终老 提交于 2019-12-02 20:44:11

When I reproduce your situation I see different PIDs between docker top <container> and docker exec -it <container> ps -aux. When you do docker exec the command is executed inside the container => should use container's pid. Otherwise you could do the kill without docker straight from the host, in your case: sudo kill -9 25055.

check this:

ps | grep -i a66 | tr -s ' '|cut -f2 -d' '|
{
    while read line;
    do kill -9 $line;
    done
}

to understand this start from executing commands from left till end of each pipe (|)

Simpler option:

kill $(pidof a66) 

Took me a while to find the right answer, but you will have to manage this process from within the container. When you run docker top a66 from the host, the PIDs are from your host, although that's not quite the case if using Cygwin. Regardless, you will need to bash or what-have-you back into your container and use commands like ps aux and kill while in the container to find and manage the different PIDs for the same processes there.

i was looking for something like this, but i couldn't find and then i did this:

[root@notebook ~]# docker exec -it tadeu_debian ps aux | grep ping | awk '{ print $2 }' | xargs -I{} docker exec -i tadeu_debian kill -9

It was two "execs" from Docker e one xargs.

Well, i hope this helps someone!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!