I am doing some tests on docker and containers and I was wondering:
Is there a method I can use to find all process associated with a docker container by its name or ID from the host point of view.
After all, at the end of the day a container is set of virtualized processes.
You can use
docker top
command. This command lists all processes running within your container.For instance this command on a single process container on my box displays:
All methods mentioned by others are also possible to use but this one should be easiest.
Update:
To simply get the main process id within the container use this command:
docker-proxy
.docker ps
will list docker containers that are running.docker exec <id|name> ps
will tell you the processes it's running.Another way to get an overview of all Docker processes running on a host is using generic cgroup based systemd tools.
systemd-cgls
will show all our cgroups and the processes running in them in a tree-view, like this:As every Docker container has its own cgroup, you can also see Docker Containers and their corresponding host processes this way.
Two interesting properties of this method:
You can also use
systemd-cgtop
to get an overview of the resource usage of Docker Containers, similar totop
.By the way: Since systemd services also correspond to cgroups these methods are also applicable to non-Dockerized systemd services.
Docker stats "container id" Shows the resource consumption along with pid or simply Docker ps .
Probably this cheat sheet can be of use. http://theearlybirdtechnology.com/2017/08/12/docker-cheatsheet/