How to kill process inside container? Docker top command

I have simple example from official guide at docker website.

I run the following:

  • Best practices for debugging vagrant+docker+flask
  • Docker ERROR: Volume specifies nonexistent driver inmemory
  • How to “add” the proxy section to configure a registry as a pull-through cache?
  • Multiple docker containers as web server on a single IP
  • Connection refused when try to connect http server in docker daemon container
  • What is equivalent remote api command to 'docker run -d'?
  • sudo docker run -d ubuntu:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"

    Then take some output from created container:

    sudo docker logs a66

    Then I lookup the running processes of a container:

    sudo docker top a66
    UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
    root                25055               15152               0                   20:07               ?                   00:00:00            /bin/sh -c while true; do echo hello world; sleep 1; done
    root                25295               25055               0                   20:10               ?                   00:00:00            sleep 1

    Next I try to kill the first process of container:

    sudo docker exec a66 kill -9 25055

    However after I make it nothing changes. Process still works and output “hello” every second. What do I wrong?

  • Docker container with Neo4j 2.3 enterprise edition exits without error message when mounting graph.db volume
  • npm ERR! Linux 4.1.19-boot2docker
  • linux container display wrong information
  • IBM Bluemix authentication token always invalid
  • Kubernetes/Spring Cloud Dataflow stream > is ignored by producer
  • How to avoid copying all the docker context directory?
  • 4 Solutions collect form web for “How to kill process inside container? Docker top command”

    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;

    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!

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.