Go 的编译结果基本上只依赖libc(传言,第三方库是否依赖那就另当别论了), 所以Docker image 实际可以做的很小
解决方法的话就是使用docker 的multi stage build, 具体的docker file 如下
# build FROM golang:1.12-alpine AS builder WORKDIR /go/src/App COPY . . # set go mod proxy ENV GO111MODULE=on ENV GOPROXY=https://goproxy.io RUN go build -ldflags "-w -s" # runtime FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ # using build result COPY --from=builder /go/src/app/ . CMD ["./appname"]