title: How to run go server on docker from binary
body: <p>I have been trying to make a Dockerfile, that would let me build my go server as binary and then run it either from the scratch image or alpine. The server works fine locally, on macOS 10.13.5, and I made it work when it wasn't from binary on Docker. </p>
  
  <p>I keep getting this error:</p>
  
  <blockquote>
    <p>standard_init_linux.go:190: exec user process caused "exec format error"</p>
  </blockquote>
  
  <p>I have been googling around and found something about system architecture. I am not sure how to check if that is the error and/or how to fix it. </p>
  
  <p>Any hints for debugging or possible fix are much appreciated.</p>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM golang:1.10.3 as builder
  WORKDIR /go/src/gitlab.com/main/server
  COPY . .
  RUN go get -d -v ./...
  RUN CGO_ENABLED=0 GOOS=linux go build -a -o main .
  
  FROM scratch
  ADD main /
  CMD ["/main"]
  </code></pre>
  
  <p>The output:</p>
  
  <pre><code>Building go
  Step 1/9 : FROM golang:1.10.3 as builder
   ---&gt; 4e611157870f
  Step 2/9 : WORKDIR /go/src/gitlab.com/main/server
  Removing intermediate container 20cd4d66008b
   ---&gt; 621d9fc02dde
  Step 3/9 : COPY . .
   ---&gt; cab639571baf
  Step 4/9 : RUN go get -d -v ./...
   ---&gt; Running in 7681f9adc7b2
  Removing intermediate container 7681f9adc7b2
   ---&gt; 767a4c9dfb94
  Step 5/9 : RUN go build -a -installsuffix cgo -o main .
   ---&gt; Running in a6ec73121163
  Removing intermediate container a6ec73121163
   ---&gt; b9d7d1c0d2f9
  Step 6/9 : FROM alpine:latest
   ---&gt; 11cd0b38bc3c
  Step 7/9 : WORKDIR /app
   ---&gt; Using cache
   ---&gt; 6d321d334b8f
  Step 8/9 : COPY . .
   ---&gt; 048a59fcdd8f
  Step 9/9 : CMD ["/app/main"]
   ---&gt; Running in d50d174644ff
  Removing intermediate container d50d174644ff
   ---&gt; 68f8f3c6cdf7
  Successfully built 68f8f3c6cdf7
  Successfully tagged main_go:latest
  Creating go ... done
  Attaching to go
  go           | standard_init_linux.go:190: exec user process caused "exec format error"
  go exited with code 1
  </code></pre>