karalabe / xgo

Go CGO cross compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow to pass flags to `docker run`

sungwoncho opened this issue · comments

commented

It would be useful to be able to pass a flag to docker run.

A use case is passing flags such as --net=host to be able to access the Internet from inside a docker container. I had a case in which xgo was failing because it could not fetch go modules for a project due to some DNS-related issue preventing the Internet from being available inside a container. The error was something like:

go: github.com/Azure/azure-pipeline-go@v0.2.2: Get https://proxy.golang.org/github.com/%21azure/azure-pipeline-go/@v/v0.2.2.mod: dial tcp: lookup proxy.golang.org on 8.8.4.4:53: read udp 172.17.0.2:452 598->8.8.4.4:53: i/o timeout

I have managed to bypass it by forking the project, and adding "--net", "host" to

xgo/xgo.go

Lines 284 to 301 in c5ccff8

args := []string{
"run", "--rm",
"-v", folder + ":/build",
"-v", depsCache + ":/deps-cache:ro",
"-e", "REPO_REMOTE=" + config.Remote,
"-e", "REPO_BRANCH=" + config.Branch,
"-e", "PACK=" + config.Package,
"-e", "DEPS=" + config.Dependencies,
"-e", "ARGS=" + config.Arguments,
"-e", "OUT=" + config.Prefix,
"-e", fmt.Sprintf("FLAG_V=%v", flags.Verbose),
"-e", fmt.Sprintf("FLAG_X=%v", flags.Steps),
"-e", fmt.Sprintf("FLAG_RACE=%v", flags.Race),
"-e", fmt.Sprintf("FLAG_TAGS=%s", flags.Tags),
"-e", fmt.Sprintf("FLAG_LDFLAGS=%s", flags.LdFlags),
"-e", fmt.Sprintf("FLAG_BUILDMODE=%s", flags.Mode),
"-e", "TARGETS=" + strings.Replace(strings.Join(config.Targets, " "), "*", ".", -1),
}

What do you think about adding a flag in xgo such as -dockerflag? I am happy to make a PR.