go install fail to generate binary

There are two folds to this problem:

1) Go install not able to generate binary

  • Kinesis agent install in docker fails on missing mirrors
  • Best practices for certificates in docker
  • Can't Access Spring Boot API in docker container
  • Run mongo shell script in mongo docker container
  • EADDRNOTAVAIL when Dockerizing Node.js app
  • Manipulating network traffic between containers in Docker in Docker environment without privileged mode?
  • go version go1.7.3 linux/amd64
    go env:
    GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/opt/gopath" GORACE="" GOROOT="/opt/go" GOTOOLDIR="/opt/go/pkg/tool/linux_amd64" CC="gcc" GOGCCFLAGS="-fPIC
    -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build831334660=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1"

    Source of the program: https://github.com/hyperledger/fabric

    Working dir: /opt/gopath/src/github.com/hyperledger/fabric

    Main program to build: /opt/gopath/src/github.com/hyperledger/fabric/peer/main.go

    Build command:

    CGO_ENABLED=0 GOBIN=/opt/gopath/bin go install -x -ldflags " -X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-snapshot-d6fbfcf -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.0 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger -linkmode external -extldflags -static -lpthread" github.com/hyperledger/fabric/peer

    I expect the binary built in /opt/gopath/bin but there was nothing there.

    It shows on the console that series of .a files were built and moved to /opt/gopath/pkg/linux_amd64/
    Eventually program stopped and no binary was built.
    This is true regardless CGO_ENABLED was set to 0 or 1.

    Somehow the program thoughts it was done, without linking the object files and building the binary? Any other debugging measures that I can use to look further into it?

    2) The ‘Go install’ command was taken from Makefile

    @$(DRUN) \
    -v $(abspath build/docker/bin):/opt/gopath/bin \
    -v $(abspath build/docker/$(TARGET)/pkg):/opt/gopath/pkg \
    hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) \
    go install -compiler gccgo -ldflags "$(DOCKER_GO_LDFLAGS)" $(pkgmap.$(@F))
    DRUN = docker run -i --rm $(DOCKER_RUN_FLAGS) \
    -v $(abspath .):/opt/gopath/src/$(PKGNAME) \
    -w /opt/gopath/src/$(PKGNAME)

    The 'Go install' command was run inside a docker container, which was started the same way the Makefile specified. The only difference was that I was doing it manually, in two shots, i.e. start docker container + go install. If I were to build it with Makefile in one shot, it would work just fine.

    Is there any catch/caveat on using this 'docker run <image> go install <args>' style command?

  • Online image building service for Arduino using Rails
  • Docker Symfony 1.4 strange missing “/” error
  • Yum install won't work on a boot2docker host?
  • Docker+Mesos+Marathon on windows 7/8/10
  • Docker does not want to install vim into my container image
  • Apply changes to docker container after 'exec' into it
  • Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.