查找Docker容器进程? (从主持人的角度来看) [英] Finding Docker container processes? (from host point of view)

查看:103
本文介绍了查找Docker容器进程? (从主持人的角度来看)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对docker和容器进行一些测试,我想知道:

I am doing some tests on docker and containers and I was wondering:

是否有一种方法可以用来从主机的角度通过其名称或ID 查找与Docker容器关联的所有进程.

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 a set of virtualized processes.

推荐答案

您可以使用docker top命令. 该命令列出了容器中正在运行的所有进程.

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:

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                14097               13930               0                   23:17               pts/6               00:00:00            /bin/bash

也可以使用其他人提到的所有方法,但这应该是最简单的.

All methods mentioned by others are also possible to use but this one should be easiest.

更新:

要简单地获取容器内的主进程ID,请使用以下命令:

To simply get the main process id within the container use this command:

 docker inspect -f '{{.State.Pid}}' <container id>

这篇关于查找Docker容器进程? (从主持人的角度来看)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆