Hacker News new | past | comments | ask | show | jobs | submit login

You can remove CGO_ENABLED=0 by using the Go Alpine image (golang:1.10-alpine). The issue is caused by Alpine images being musl libc based.



Using the `golang:1.10-alpine` image to run your binary would defeat the purpose of a multi-stage build, since it includes everything needed to compile Go and weighs in around 376MB. The `alpine:3.7` image is about 4MB.

edit

I misunderstood the parent, they meant to use `golang:1.10-alpine` as the build image, not the run image, as in:

    FROM golang:1.10-alpine
    COPY . /go/src/bitbucket.code.company-name.com.au/scm/code
    WORKDIR /go/src/bitbucket.code.company-name.com.au/scm/code/
    RUN go build main.go

    FROM alpine:3.7
    RUN apk add --no-cache ca-certificates
    COPY --from=0 /go/src/bitbucket.code.company-name.com.au/scm/code/main .
    CMD ["./main"]
Which works! Thank you!


No, use golang:1.10-alpine for the build, keep the second stage the same.


I had some weird issues trying to cross-compile to alpine, but using the golang-alpine image fixed them all.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: