栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

docker容器内-树状默认查看

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

docker容器内-树状默认查看

一.以attach进入容器并运行进程

1、docker attach 容器id  #以上帝进程进入容器
   当前进程中身份是上帝进程
2、[root@c430d0de2d57 /]# /usr/sbin/httpd -DFOREGROUND  #启动apache
   AH00558: httpd: Could not reliably determine the server's fully qualified domain name, 
   using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

3、此时容器内新运行的服务是挂在上帝进程下的,另起终端进行查看
[root@docker ~]# docker exec -it c430d0de2d57 /bin/bash #exec为启动新的进程连接

4、[root@c430d0de2d57 /]# pstree -p  #此时执行树状,程序识别码不指定默认输出为1(即上帝进程)
   bash(1)---httpd(198)-+-httpd(199)
                        |-httpd(200)
                        |-httpd(201)
                        |-httpd(202)
                        `-httpd(203)

二、以exec进入容器并运行进程

1、[root@docker ~]# docker exec -it c430d0de2d57 /bin/bash  #以exec新起进程方式进入容器
2、[root@c430d0de2d57 /]# /usr/sbin/httpd -DFOREGROUND   #前台启动进程
   AH00558: httpd: Could not reliably determine the server's fully qualified domain name, 
   using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
3、此时容器内新运行的服务是挂在新起进程下的,另起终端进行查看
   [root@docker ~]# docker exec -it c430 /bin/bash

4、[root@c430d0de2d57 /]# pstree -p #默认查看的是上帝进程
   bash(1)

5、[root@c430d0de2d57 /]# ps -aux     #显示所有包含其他使用者的行程
    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root          1  0.0  0.0  11820  1876 pts/0    Ss   05:24   0:00 /bin/bash
    root        27  0.0  0.0  11820  1880 pts/2    Ss   06:20   0:00 /bin/bash
    root        189  0.8  0.4 310448 11892 pts/0    S+   06:24   0:00 /usr/sbin/httpd -        DFOREGROUND
    apache      190  0.0  0.2 310448  6104 pts/0    S+   06:24   0:00 /usr/sbin/httpd -DFOREGROUND
    apache      191  0.0  0.2 310448  6104 pts/0    S+   06:24   0:00 /usr/sbin/httpd -DFOREGROUND
    apache      192  0.0  0.2 310448  6104 pts/0    S+   06:24   0:00 /usr/sbin/httpd -DFOREGROUND
    apache      193  0.0  0.2 310448  6104 pts/0    S+   06:24   0:00 /usr/sbin/httpd -DFOREGROUND
    apache      194  0.0  0.2 310448  6104 pts/0    S+   06:24   0:00 /usr/sbin/httpd -DFOREGROUND
    root        195  0.0  0.0  51708  1724 pts/2    R+   06:25   0:00 ps -aux

6、[root@c430d0de2d57 /]# pstree -p 27   #通过指定进程识别码进行查看
   bash(27)---httpd(179)-+-httpd(180)
                         |-httpd(181)
                         |-httpd(182)
                         |-httpd(183)
                         `-httpd(184)

三、总结

       1、 attach连接的是上帝进程

        2、exec 则是启动新的进程连接,自定义运行新的命令与上帝进程无关

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/705411.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号