Skip to content
New issue

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

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

Already on GitHub? # to your account

Any ideas about that why this code is not working in a Docker container. #12

Open
BerkeSoysal opened this issue Apr 6, 2022 · 2 comments

Comments

@BerkeSoysal
Copy link

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?

@BerkeSoysal BerkeSoysal changed the title Any ideas this doesn't work in a Docker container. Any ideas about that why this code is not working in a Docker container. Apr 6, 2022
@aahemm
Copy link

aahemm commented Jun 6, 2022

What error do you get? I think it is because your container is not run in privileged mode. Try running it in privileged mode.

@gvu0110
Copy link

gvu0110 commented Dec 27, 2022

@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

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

No branches or pull requests

3 participants