Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code-5.4 运行exec时,nsenter报错 #79

Open
yuanshuli11 opened this issue Dec 29, 2020 · 4 comments
Open

Code-5.4 运行exec时,nsenter报错 #79

yuanshuli11 opened this issue Dec 29, 2020 · 4 comments

Comments

@yuanshuli11
Copy link

yuanshuli11 commented Dec 29, 2020

环境:
Linux version 5.7.13-1.el7.x86_64 (root@1801e27a3031) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC), GNU ld version 2.27-43.base.el7_8.1) #1 SMP Thu Aug 6 05:07:46 UTC 2020
centos7

报错内容:
`
☁ mydocker ./mydocker exec neo sh
{"level":"info","msg":"container pid 2139","time":"2020-12-29T21:51:02+08:00"}
{"level":"info","msg":"command sh","time":"2020-12-29T21:51:02+08:00"}
got mydocker_pid=2139
got mydocker_cmd=sh
setns on ipc namespace failed: Bad file descriptor
setns on uts namespace failed: Bad file descriptor
setns on net namespace failed: Bad file descriptor
setns on pid namespace failed: Bad file descriptor
setns on mnt namespace failed: Bad file descriptor

`
本身是没发现错误的,但是因为在容器中ps -ef仍能看到宿主机的进程。所以打开了 nsenter的fprintf。 然后就报这个错误。

看样子是因为setns 隔离命名空间失败了,但为什么呢? 求教啊

@yuanshuli11
Copy link
Author

现象是当执行完 ./mydocker run 后 2139 进程就已经挂掉了吧。 所以才会nsenter 失败。 。

@JaydenChang
Copy link

JaydenChang commented May 6, 2023

我用的WSL,我每运行一次容器,就去查看有没有top进程,直到有top进程后,我再去执行exec,除了mnt其他四个都可以成功执行,mnt的错误提示是:Stale file handle,不知道楼主有没有这样的情况

@JaydenChang
Copy link

我用的WSL,我每运行一次容器,就去查看有没有top进程,直到有top进程后,我再去执行exec,除了mnt其他四个都可以成功执行,mnt的错误提示是:Stale file handle,不知道楼主有没有这样的情况

后面不知道为什么,重新敲了一遍代码,又切换回去,又能过了,楼主的代码我也试过,cgo那里缺点东西,在作者的另一个issue那里有解决方案,楼主的问题应该是,运行 -d top 时,top没有在后台运行,可能要多运行几次,通过 ps -ef去查看,有运行了才能通过exec进入容器内部

@guohaonan-shy
Copy link

先请教下楼上的朋友,我run起来一个容器进程之后,也出现bad filedescriptor 这个错误了,我发现对应的ns目录,并没有容器进程的目录,这是直接原因;想请教下,为什么创建容器进程会没有产生这个目录呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants