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.

Dockerfile

Be sure to replace "cmd/server/server.go" with your main file.

FROM golang:1.13 as builder

WORKDIR /app
COPY . /app
RUN CGO_ENABLED=0 GOOS=linux GOPROXY=https://proxy.golang.org go build -o app cmd/server/server.go

FROM 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

Docker for Absolute Beginners

Containerizing a Node.js Application for Development With Docker Compose

How To Set Up Laravel, Nginx, and MySQL with Docker Compose

Docker Basics: Docker Compose


#docker #web-development #go

Build slim Docker images for your Go app
4 Likes25.55 GEEK