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

查看:21
本文介绍了寻找 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天全站免登陆