Skip to content

os/exec: go fmt fails inside docker container #34318

@zrma

Description

@zrma

What version of Go are you using (go version)?

$ go version
go version go1.13 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build831486306=/tmp/go-build -gno-record-gcc-switches"
r

What did you do?

run this code in docker image golang:1.13.0

binPath := runtime.GOROOT()
binPath = filepath.Join(binPath, "bin", "go")

srcPath := os.Getenv("GOPATH")
srcPath = filepath.Join(srcPath, "src", "app", "cmd", "filename.go")

cmd := exec.Command(binPath, "fmt", srcPath)
if err := cmd.Start(); err != nil {
    log.Println(err)
}
if err := cmd.Wait(); err != nil {
    // Error has occurred.
    log.Println(err)
}

What did you expect to see?

It works well.
I apply go fmt to "app/cmd/filename.go" file exactly.

What did you see instead?

In windows, golang 1.13.0 It works.
In ubuntu, WSL golang 1.13.0 It works.
In docker image golang:1.12.9, It works.
In docker image golang:1.13.0 It failed.

 <*exec.ExitError | 0xc00000e820>: {
          ProcessState: {
              pid: 1388,
              status: 256,
              rusage: {
                  Utime: {Sec: 0, Usec: 350000},
                  Stime: {Sec: 0, Usec: 240000},
                  Maxrss: 18304,
                  Ixrss: 0,
                  Idrss: 0,
                  Isrss: 0,
                  Minflt: 9364,
                  Majflt: 0,
                  Nswap: 0,
                  Inblock: 352,
                  Oublock: 7368,
                  Msgsnd: 0,
                  Msgrcv: 0,
                  Nsignals: 0,
                  Nvcsw: 15901,
                  Nivcsw: 1747,
              },
          },
          Stderr: nil,
      }
      exit status 1

If I run command in bash shell directly from cmd.String() output
(like /usr/local/go/bin/go fmt /go/src/app/cmd/filename.go) at golang:1.13.0 docker image,
it works well.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions