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

  • Docker - is it necessary to push images to remote server?
  • Docker: Add a restart policy to a container that was already created
  • Rancher with postgresql
  • Using Docker with nodejs with node-gyp dependencies
  • how to mount host directory to container VOLUME?
  • What is the relationship between a docker image ID and the IDs in the manifests?
  • 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..
    

  • Docker volumes binding: container to host
  • Get the size of a Docker image before a pull?
  • Could not find gem mysql2 even though it's in the Gemfile and bundle install is in the Dockerfile
  • How to remote desktop to a docker container with xrdp installed running on a remote server?
  • export and import docker data containers
  • What's the reason for the 42 layer limit in Docker?
  • 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.