mydocker icon indicating copy to clipboard operation
mydocker copied to clipboard

fork/exec /bin/sh: operation not permitted exit status 1

Open chengyayu opened this issue 5 years ago • 3 comments

Q1:请问项目中代码的开发环境是什么?

我使用 mac 开发,按照示例中的代码编写时,发现有些API是不兼容的。所以我采用了 remote-dev 的方式开启了一个容器,在容器中开发,这样 API 的操作系统不兼容的问题解决了。

我容器开发环境如下:go1.15.3 linux/amd64

Q2:为什么会出现 fork/exec /bin/sh: operation not permitted exit status 1?

func main() {
	cmd := exec.Command("sh")
	cmd.SysProcAttr = &syscall.SysProcAttr{Cloneflags: syscall.CLONE_NEWUTS}
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	if err := cmd.Run(); err != nil {
		log.Fatal(err)
	}
}

执行

go run main.go

报错: fork/exec /bin/sh: operation not permitted exit status 1

chengyayu avatar Oct 16 '20 02:10 chengyayu

运行的容器没有root权限,加上 --privileged 参数,才能使容器拥有root权限。

HhTtLllL avatar Dec 09 '20 05:12 HhTtLllL

运行的容器没有root权限,加上--特权参数,才能使容器拥有root权限。 他这个不是容器啊,哪来的--privileged参数啊,只是没有权限获取系统的CLONE_NEWUTS,sudo就可以了

xChen16 avatar Aug 12 '21 00:08 xChen16

如果要在一个ubuntu的docker容器中运行的mydocker,需要--privileged

ForeverSRC avatar Dec 13 '21 02:12 ForeverSRC