运行容器:
[root@localhost ~]# docker run -it centos:7.7.1908 /bin/bash
[root@79d4ba3a2080 /]#
主机执行:
[root@localhost ~]# ps aux|grep /bin/bash
root 10124 0.0 2.7 385800 51548 pts/1 Sl+ 14:25 0:00 docker run -it centos:7.7.1908 /bin/bash
root 10155 0.0 0.0 11828 1740 pts/0 Ss+ 14:25 0:00 /bin/bash
root 10197 0.0 0.0 112728 976 pts/2 S+ 14:27 0:00 grep --color=auto /bin/bash
查看容器运行过程fd: 容器运行过程(stdin,stdout,stderr)指向pts / 0。
[root@localhost ~]# ll /proc/10155/fd
total 0
lrwx------ 1 root root 64 May 8 14:25 0 -> /dev/pts/0
lrwx------ 1 root root 64 May 8 14:25 1 -> /dev/pts/0
lrwx------ 1 root root 64 May 8 14:25 2 -> /dev/pts/0
lrwx------ 1 root root 64 May 8 14:29 255 -> /dev/pts/0
测试1:
[root@localhost ~]# echo "hello" > /proc/10155/fd/0
容器显示结果:
[root@79d4ba3a2080 /]# hello
测试2:
[root@localhost ~]# echo "hello" > /dev/pts/0
主机显示结果:
[root@localhost ~]# tty
/dev/pts/0
[root@localhost ~]# hello
结果表明,在主机pts / 0中,容器没有响应。
“测试2”有什么问题?
为什么它没有显示在容器中?
码头工人做了什么?
如果有任何相关信息,请告诉我,谢谢。
了解:
我用以下命令模拟了类型现象。
安装目录,由Docker CentOS 7镜像
[root@localhost test]# mount -t overlay overlay -o lowerdir=/var/lib/docker/overlay2/e6e24960aabfb790c893d0d1e419cb34f97b92824941ab74b01348ef96c99412-init/diff:/var/lib/docker/overlay2/075bf06b50f9bc5fc2111b5e1c831f7f1304e3310a448e323e71ca9e7d83ba55/diff,upperdir=/var/lib/docker/overlay2/e6e24960aabfb790c893d0d1e419cb34f97b92824941ab74b01348ef96c99412/diff,workdir=/var/lib/docker/overlay2/e6e24960aabfb790c893d0d1e419cb34f97b92824941ab74b01348ef96c99412/work /project/test/t222
创建Pid名称空间:
[root@localhost t222]# unshare -u -i -p -m -n -f --mount-proc /bin/bash
[root@localhost t222]# pivot_root . .
[root@localhost t222]# for e in "proc proc proc/" "sysfs sysfs sys/" "devtmpfs devtmpfs dev/" "devpts devpts dev/pts/" ; do mount -t ${e} ; done
[root@localhost t222]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
overlay overlay 17G 14G 3.8G 79% /
devtmpfs devtmpfs 898M 0 898M 0% /dev
测试文件:
在新的命名空间中:
[root@localhost t222]# vi 123.txt
在主持人中:
[root@localhost ~]# ps -ef
'''
root 28295 28030 0 5月10 pts/4 00:00:00 unshare -u -i -p -m -n -f --mount-proc /bin/bash
root 28297 28295 0 5月10 pts/4 00:00:00 /bin/bash
root 29921 28297 0 09:52 pts/4 00:00:00 vi 123.txt
查看过程信息:
[root@localhost ~]# ll /proc/28295/cwd
lrwxrwxrwx 1 root root 0 5月 11 09:52 /proc/28295/cwd -> /
[root@localhost ~]# ll /proc/28297/cwd
lrwxrwxrwx 1 root root 0 5月 11 09:52 /proc/28297/cwd -> /
[root@localhost ~]# ll /proc/30272/cwd
lrwxrwxrwx 1 root root 0 5月 11 10:06 /proc/30272/cwd -> /
[root@localhost ~]# ll /proc/30272/fd
total 0
lrwx------ 1 root root 64 5月 11 10:06 0 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 1 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 2 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 3 -> /.123.txt.swp [red, soft connection does not exist]
[root@localhost ~]# touch /.123.txt.swp
[root@localhost ~]# ll /proc/30272/fd
total 0
lrwx------ 1 root root 64 5月 11 10:06 0 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 1 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 2 -> /dev/pts/4
lrwx------ 1 root root 64 5月 11 10:06 3 -> /.123.txt.swp [normal]
摘要:
在主机中看到的过程信息是新名称空间中的过程信息,“ ll / proc / 30272 / fd”表明不存在软连接,它基于旧名称空间,主要是“ pivot_root ”,修改了当前所有进程的运行目录