I realize that processes that run inside Docker containers appear on the hosts' process list:
# ps aux | grep mariadb
root 12486 0.0 0.0 112812 976 pts/0 S+ 14:47 0:00 grep --color=auto mariadb
Is there a way to identify whether a process is running on the Host or on a Docker container, or a way to filter the Docker processes out?
If I quickly want to see what processes were started by what, I typically use a tool like
htop
(in tree mode by pressing F5), orpstree
.The output from
pstree
will look a bit like this:Which easily shows what processes are started by what.
htop
lives within the in EPEL Repo, on RHEL.pstree
is installed by thepsmisc
package.This isn't the most technical answer, but the best answer seems to already exist in a comment.
Found the answer.
To filter processes that are not running in Docker processes, we can use this:
ps -e -o pid,comm,cgroup | grep -v "/docker/"
So, for example, if I want to kill all "php-fpm" processes that are not running inside Docker, I can do:
kill -9 $(ps -e -o pid,comm,cgroup | grep -v "/docker/" | awk '$2 == "php-fpm" {print $1}')