standard_init_linux.go:190: exec user process caused “no such file or directory” Docker with go basic web app

前端 未结 5 2028
野性不改
野性不改 2020-12-21 07:32

The very basic web app is created in Go

package main

import(
   "fmt"
   "net/http"
   "os"
)

func hostHandler(w http.Response         


        
5条回答
  •  别那么骄傲
    2020-12-21 07:44

    In my case CGO_ENABLED=0 was the key to fix this problem.

    Cgo allows to use inline C code in Go sources, see more: https://golang.org/cmd/cgo/

    I reckon by default Cgo links your application dynamically to libc, even if you don't use any inline C.
    And libc is missing when you package your application to Docker image FROM scratch

    Here is my working Dockerfile:

    FROM golang:1.9.2-alpine AS builder
    WORKDIR /go/src/app
    COPY . .
    RUN CGO_ENABLED=0 go install
    
    
    FROM scratch
    WORKDIR /opt
    COPY --from=builder /go/bin/app .
    ENTRYPOINT ["/opt/app"]
    

提交回复
热议问题