修改Dockerfile,使得构建出的docker镜像仅为17.4M

This commit is contained in:
sunrise 2023-02-10 04:25:04 +08:00
parent 8d830a424a
commit 025f2306a3

View File

@ -1,13 +1,20 @@
FROM golang:1.19-alpine FROM golang:1.19-alpine as builder
ENV api_key="" RUN apk --no-cache add git && export GOPRIVATE=github.com/houko/wechatgpt && \
export GOPROXY=https://goproxy.cn,direct
RUN export GOPRIVATE=github.com/houko/wechatgpt COPY . /root/build
WORKDIR /app WORKDIR /root/build
COPY . /app
RUN go mod download && go build -o server main.go RUN go mod download && go build -o server main.go
CMD ./server FROM alpine:latest as prod
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /root/build/server .
CMD ["./server"]