<p>I've the following docker file which is working for my application. I was able to access to the simple web app server.</p>
<pre><code>FROM golang:1.14.7 AS builder
RUN go get github.com/go-delve/delve/cmd/dlv
RUN mkdir /app

ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -gcflags=&quot;all=-N -l&quot; -o main ./...

FROM alpine:3.12.0 AS production
COPY --from=builder /app .
EXPOSE 8000 40000
ENV PORT=8000
CMD [&quot;./main&quot;]
</code></pre>
<p>When I adopt it like following, I am not able to deploy it successfully to Kubernetes. The container crashed with some general error, not something that I can use.</p>
<pre><code>standard_init_linux.go:190: exec user process caused &quot;no such file or directory&quot;
</code></pre>
<p><strong>This not working</strong></p>
<pre><code>FROM golang:1.14.7 AS builder
RUN go get github.com/go-delve/delve/cmd/dlv
RUN mkdir /app

ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -gcflags=&quot;all=-N -l&quot; -o main ./...

FROM alpine:3.12.0 AS production
COPY --from=builder /app .
COPY --from=builder /go/bin/dlv /
EXPOSE 8000 40000
ENV PORT=8000
CMD [&quot;/dlv&quot;, &quot;--listen=:40000&quot;, &quot;--headless=true&quot;, &quot;--api-version=2&quot;, &quot;--accept-multiclient&quot;, &quot;exec&quot;, &quot;./main&quot;]
</code></pre>
<p>If someone want to try it out this is the simple program (this is minimum reproducible  example), if you take the first docker file it will work for you, for the second it does not.</p>
<pre class="lang-golang prettyprint-override"><code>package main

import (
    &quot;fmt&quot;
    &quot;net/http&quot;
    &quot;os&quot;
)

func main() {
    fmt.Println(&quot;app is starting!&quot;)

    var port string
    if port = os.Getenv(&quot;PORT&quot;); len(port) == 0 {
        port = &quot;8080&quot;
    }
    http.HandleFunc(&quot;/&quot;, handler)
    http.ListenAndServe(&quot;:&quot;+port, nil)

}

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, &quot;Hi there,  %s!&quot;, r.URL.Path[1:])
}
</code></pre>

PJEM
<p>You need to compile <code>dlv</code> itself with the static linking flags. Without that, <code>dlv</code> will have dynamic links to libc which doesn't exist within an alpine image. Other options include switching your production image to be debian based (<code>FROM debian</code>) or change to golang image to be alpine based (<code>FROM golang:1.14.7-alpine</code>). To compile <code>dlv</code> without dynamic links, the following Dockerfile works:</p>
<pre><code>FROM golang:1.14.7 AS builder
RUN CGO_ENABLED=0 go get -ldflags '-s -w -extldflags -static' github.com/go-delve/delve/cmd/dlv
RUN mkdir /app

ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -gcflags=&quot;all=-N -l&quot; -o main ./...

FROM alpine:3.12.0 AS production
COPY --from=builder /app .
COPY --from=builder /go/bin/dlv /
EXPOSE 8000 40000
ENV PORT=8000
CMD [&quot;/dlv&quot;, &quot;--listen=:40000&quot;, &quot;--headless=true&quot;, &quot;--api-version=2&quot;, &quot;--accept-multiclient&quot;, &quot;exec&quot;, &quot;./main&quot;]    
</code></pre>
<p>To see the dynamic links, build your builder image and run <code>ldd</code> against the output binaries:</p>
<pre><code>$ docker build --target builder -t test-63403272 .
[+] Building 4.6s (11/11) FINISHED                                                                                                                                                                                 
 =&gt; [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 =&gt; =&gt; transferring dockerfile: 570B                                                                                                                                                                          0.0s
 =&gt; [internal] load .dockerignore                                                                                                                                                                             0.0s
 =&gt; =&gt; transferring context: 2B                                                                                                                                                                               0.0s
 =&gt; [internal] load metadata for docker.io/library/golang:1.14.7                                                                                                                                              0.2s
 =&gt; [builder 1/6] FROM docker.io/library/golang:1.14.7@sha256:1364cfbbcd1a5f38bdf8c814f02ebbd2170c93933415480480104834341f283e                                                                                0.0s
 =&gt; [internal] load build context                                                                                                                                                                             0.0s
 =&gt; =&gt; transferring context: 591B                                                                                                                                                                             0.0s
 =&gt; CACHED [builder 2/6] RUN go get github.com/go-delve/delve/cmd/dlv                                                                                                                                         0.0s
 =&gt; CACHED [builder 3/6] RUN mkdir /app                                                                                                                                                                       0.0s
 =&gt; [builder 4/6] ADD . /app                                                                                                                                                                                  0.1s
 =&gt; [builder 5/6] WORKDIR /app                                                                                                                                                                                0.0s
 =&gt; [builder 6/6] RUN CGO_ENABLED=0 GOOS=linux go build -gcflags=&quot;all=-N -l&quot; -o main ./...                                                                                                                    4.0s
 =&gt; exporting to image                                                                                                                                                                                        0.2s
 =&gt; =&gt; exporting layers                                                                                                                                                                                       0.2s
 =&gt; =&gt; writing image sha256:d2ca7bbc0bb6659d0623e1b8a3e1e87819d02d0c7f0a0762cffa02601799c35e                                                                                                                  0.0s
 =&gt; =&gt; naming to docker.io/library/test-63403272                                                                                                                                                              0.0s

$ docker run -it --rm test-63403272 ldd /go/bin/dlv
        linux-vdso.so.1 (0x00007ffda66ee000)
        libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007faa4824d000)
        libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007faa4808c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007faa48274000)
</code></pre>
<p>Libc is a common missing library when switching to alpine since it uses musl by default.</p>
