I'm using Go 1.13 and the community module proxy to build the binary and Alpine as a base image. It adds a user and group instead of running as root.
Be sure to replace "cmd/server/server.go" with your main file.
FROM golang:1.13 as builderWORKDIR /app
COPY . /app
RUN CGO_ENABLED=0 GOOS=linux GOPROXY=https://proxy.golang.org go build -o app cmd/server/server.goFROM alpine:latest
mailcap adds mime detection and ca-certificates help with TLS (basic stuff)
RUN apk --no-cache add ca-certificates mailcap && addgroup -S app && adduser -S app -G app
USER app
WORKDIR /app
COPY --from=builder /app/app .
ENTRYPOINT [ “./app” ]
I hope this is helpful. I mostly blogged this to document it for myself.
Originally published by Andri at andri.dk
=============================
Thanks for reading
If you liked this post, share it with all of your programming buddies!
Follow me on Facebook | Twitter
Containerizing a Node.js Application for Development With Docker Compose
How To Set Up Laravel, Nginx, and MySQL with Docker Compose
#docker #web-development #go