Any ideas about that why this code is not working in a Docker container.
BerkeSoysal opened this issue · comments
Since i don't have a linux env, i thought it would be a good idea to make this tutorial in a containerized ubuntu env.
So after docker run -it ubuntu and installing golang,
package main
import ("os"
"fmt"
"os/exec"
"syscall"
)
func main() {
switch os.Args[1] {
case "run":
run()
default:
panic("Bad command")
}
}
func run() {
fmt.Printf("Running %v\n", os.Args[2:])
cmd := exec.Command(os.Args[2], os.Args[3:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.SysProcAttr = &syscall.SysProcAttr {
Cloneflags: syscall.CLONE_NEWUTS,
}
cmd.Run()
}
I came until this part, but after adding
cmd.SysProcAttr = &syscall.SysProcAttr {
Cloneflags: syscall.CLONE_NEWUTS,
}
It is no longer running the command on the argument. Any ideas?
What error do you get? I think it is because your container is not run in privileged mode. Try running it in privileged mode.
@BerkeSoysal Not sure what error you're facing. But for your main.go
, it will work as
docker run --rm -it --mount src=
pwd,target=/go/src,type=bind golang:1.19.4 bash
I would suggest going with a Linux VM in any cloud provider for later experiments such as proc
mount or resource constraints, since they don't work in a Docker container