docker process tree

简介:
使用sshd这个镜像来简单的介绍一下container和宿主机的进程树结构 : 
首先使用前面我们创建的sshd镜像, 启动一个container, 
http://blog.163.com/digoal@126/blog/static/1638770402014102711413675/
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                COMMAND               CREATED             STATUS              PORTS               NAMES
74e5b4373374        digoal/sshd:latest   "/usr/sbin/sshd -D"   29 minutes ago      Up 29 minutes       22/tcp              digoal  

container对应的IP和PID如下 : 
[root@localhost ~]# docker inspect digoal
        "IPAddress": "172.17.0.22",
        "Pid": 8378,

登录到container, 并启动一个postgresql server, 便于查看进程结构.
[root@localhost ~]# ssh 172.17.0.22
root@172.17.0.22's password: 
Last login: Thu Nov 27 13:32:37 2014 from 172.17.42.1

在container内部, pid=1的进程是docker 的entrypoint或cmd执行的命令, 例如sshd的镜像执行的是sshd -D.
[root@74e5b4373374 ~]# ps -ewf|grep 1
root         1     0  0 13:32 ?        00:00:00 /usr/sbin/sshd -D

在container内启动的其他进程是继承自PID1的, 即sshd -D进程.
postmaster进程继承自sshd, postmaster的其他子进程继承自postmaster.

[root@74e5b4373374 ~]# ps -ewfjH|grep postgres
postgres   288     1   285     8  0 13:35 ?        00:00:00   /usr/bin/postgres
postgres   289   288   289   289  0 13:35 ?        00:00:00     postgres: logger process  
postgres   291   288   291   291  0 13:35 ?        00:00:00     postgres: checkpointer process  
postgres   292   288   292   292  0 13:35 ?        00:00:00     postgres: writer process  
postgres   293   288   293   293  0 13:35 ?        00:00:00     postgres: wal writer process  
postgres   294   288   294   294  0 13:35 ?        00:00:00     postgres: autovacuum launcher process  
postgres   295   288   295   295  0 13:35 ?        00:00:00     postgres: stats collector process 

在宿主机上看的话, container继承自docker server, container中的其他进程继承自container cmd或entrypoint调用.
# ps -ewfjH|grep postgres
root      4661     1  4661  4661  1 19:23 ?        00:02:14   /usr/bin/docker -d --selinux-enabled=false -g /data01/docker
root      8378  4661  8378  8378  0 21:32 ?        00:00:00     /usr/sbin/sshd -D
26        8840  8378  8837  8458  0 21:35 ?        00:00:00       /usr/bin/postgres
26        8841  8840  8841  8841  0 21:35 ?        00:00:00         postgres: logger process  
26        8843  8840  8843  8843  0 21:35 ?        00:00:00         postgres: checkpointer process  
26        8844  8840  8844  8844  0 21:35 ?        00:00:00         postgres: writer process  
26        8845  8840  8845  8845  0 21:35 ?        00:00:00         postgres: wal writer process  
26        8846  8840  8846  8846  0 21:35 ?        00:00:00         postgres: autovacuum launcher process  
26        8847  8840  8847  8847  0 21:35 ?        00:00:00         postgres: stats collector process

PID=1的进程是systemd(CentOS 7.x 是这样的)
root         1     0  0 19:03 ?        00:00:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23

如果CentOS 6.x 是init进程 : 
root         1     0  0 Nov20 ?        00:00:02 /sbin/init

关于cgroup请参考
图例 : 
docker process tree - 德哥@Digoal - PostgreSQL research
 


[参考]
目录
相关文章
|
Docker 容器
Docker服务启动失败报错:Job for docker.service failed because the control process exited with error code.
Docker服务启动失败报错:Job for docker.service failed because the control process exited with error code.
|
Kubernetes Docker 容器
Job for docker.service failed because the control process exited with error code.
Job for docker.service failed because the control process exited with error code.
2984 0
|
Unix Shell Linux
5-15|Docker报错OCI runtime exec failed: exec failed: unable to start container process: exec: “/bin/ba
5-15|Docker报错OCI runtime exec failed: exec failed: unable to start container process: exec: “/bin/ba
|
Unix Docker 容器
使用docker 启动naocs 报错出现:standard_init_linux.go:241: exec user process caused "exec format error"
```markdown Error in Docker container startup: "standard_init_linux.go:241: exec user process caused \"exec format error\"". Occurred at 2024-06-29 09:26:19.910, followed by a failed hook with a syslog delivery error at 09:27:20.193. Seeking solutions from experts. ```
|
4月前
|
缓存 前端开发 Docker
Docker Layer Caching:加速你的容器构建
Docker Layer Caching:加速你的容器构建