I'm trying to build from go stretch using -race and then copy it to the small alpine container to reduce final size. But I got this error during starting:
standard_init_linux.go:211: exec user process caused "no such file or directory"
My Dockerfile:
FROM golang:1.12.6-stretch as build-env
WORKDIR /goman/
ADD . .
RUN GOFLAGS=-mod=vendor go test -race -v ./...
RUN CGO_ENABLED=0 GOBIN=/goman/apps/ GOOS=linux GOARCH=amd64 go install -v \
-a -tags netgo -installsuffix netgo -mod vendor -ldflags "-d -s -w" ./cmd/...
FROM alpine:3.10
RUN apk add --no-cache ca-certificates tzdata
COPY --from=build-env /goman/apps/ /apps
COPY --from=build-env /goman/conf /conf
WORKDIR /apps/
I can clearly see files when sh`ing in container and the permissions are correct
Try to use go build
instead of go install
. In this case, I think, you only need to build an executable from the source, not install and build the remote one.