Static Go Binaries w/ Docker – Entrypoint Not Found

I used Static Go Binaries with Docker on OSX by Nicola Paolucci to try to use static Go binary w/ Docker. I believe I followed every step correctly, but when I run the final image, I get the following error response from Docker.

NOTE The name of my service and executable are netverify

  • Rancher with postgresql
  • How to detect a docker daemon port
  • Docker-swarm overlay network is not working for containers in different hosts
  • Published k8s service is not available
  • How to forward all ports in docker container
  • Restarting Docker Container after reboot
  • docker: Error response from daemon: Container command '/netverify' not found or does not exist..
    

    My Dockerfile.static looks like the following…

    #Create a minimal container to run a Golang static binary
    
    FROM tianon/true
    ADD netverify /
    EXPOSE 8282
    CMD ["/netverify"]
    

    My Dockerfile.build looks like the following…

    FROM golang
    
    ADD Makefile /
    WORKDIR /
    RUN make setup
    
    ADD . /go/src/github.com/eirwin/netverify
    
    RUN make buildgo
    CMD ["/bin/bash"]
    

    My Makefile is the following…

    GOCMD = go
    GOBUILD = $(GOCMD) build
    GOGET = $(GOCMD) get -v
    GOCLEAN = $(GOCMD) clean
    GOINSTALL = $(GOCMD) install
    GOTEST = $(GOCMD) test
    
    .PHONY: all
    
    all: build
    
    setup:
        $(GOGET) github.com/gorilla/mux
    
    buildgo:
        GOOS=linux $(GOBUILD) -o netverify ./go/src/github.com/eirwin/netverify
    
    builddocker:
        docker build -t eirwin/netverify -f ./Dockerfile.build .
        docker run -t eirwin/netverify /bin/true
        docker cp `docker ps -q -n=1`:/netverify .
        chmod 755 ./netverify
        docker build --rm=true --tag=eirwin/netverify -f Dockerfile.static .
    
    run:    builddocker
        docker run -p 8282:8282 eirwin/netverify    
    

    For the purpose of this post, lets assume I have the following as my golang application.

    func main() {
    
        router := mux.NewRouter()
        router.HandleFunc("/ping", api.PingHandler).Methods("GET")
        http.ListenAndServe(":8282", router)
    }
    

    When I run Make run everything seems to work except for when the image is ran.

    I can see that the image builds correctly at ~8.5MB

    eirwin/netverify  latest  eae16e146b91 3 seconds ago       8.63 MB
    

    But when If docker run -p 8282:8282 eirwin/netverify is ran I get the following error…

    docker: Error response from daemon: Container command '/netverify' not found or does not exist..
    

  • PDOException SQLSTATE[HY000] [2002] No such file or directory. Whilst running laravel via isolated docker containers
  • Is there a way to setup bluemix as $DOCKER_HOST and use it with the docker binary?
  • Reload code inside docker container. PM2. Node js
  • libGL error: failed to load driver swrast in docker container
  • docker: how to get veth bridge interface pair easily?
  • Dockerize Logstash, Redis setup
  • One Solution collect form web for “Static Go Binaries w/ Docker – Entrypoint Not Found”

    The go static build in your makefile is missing some options.

    buildgo:
        CGO_ENABLED=0 GOOS=linux go build -ldflags "-s" -a -installsuffix cgo -o netverify ./go/src/github.com/eirwin/netverify
    

    The build process can capture the container ID to avoid timing issues.
    Separate the tags for build and binary images.

    builddocker:
        docker build -t eirwin/netverify-build -f ./Dockerfile.build .
        CID=$$(docker create eirwin/netverify-build); \
        docker cp $$CID:/netverify .; \
        docker rm $$CID
        chmod 755 ./netverify
        docker build --rm=true --tag=eirwin/netverify -f Dockerfile.static .
    

    Your binary Dockerfile.static can start with the scratch blank image.

    FROM scratch
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.