wujian_develop_tool/template/service/docker/golang/Dockerfile.tpl

20 lines
551 B
Docker
Raw Permalink Normal View History

2022-01-06 23:34:37 +08:00
FROM golang:1.17 as builder
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io,direct
WORKDIR /go/cache
ADD go.mod .
ADD go.sum .
2022-01-07 00:39:21 +08:00
RUN go mod download -x
2022-01-06 23:34:37 +08:00
WORKDIR /go/src
ADD . .
RUN go mod tidy
2022-01-10 20:26:14 +08:00
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o service_{{ .Name }} ./{{ .Root }}
2022-01-06 23:34:37 +08:00
FROM reg.icechen.cn/alpine as {{ .Name }}
WORKDIR /go/src
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /go/src/service_{{ .Name }} ./
ENV TZ=Asia/Shanghai
RUN chmod +x ./service_{{ .Name }}
EXPOSE 8080
CMD ["./service_{{ .Name }}"]