1 回答

TA貢獻(xiàn)1725條經(jīng)驗(yàn) 獲得超8個(gè)贊
嘗試以下Docker文件:
# GO Repo base repo
FROM golang:1.12.0-alpine3.9 as builder
RUN apk add git
# Add Maintainer Info
LABEL maintainer="<>"
RUN mkdir /app
ADD . /app
WORKDIR /app
COPY go.mod go.sum ./
# Download all the dependencies
RUN go mod download
COPY . .
# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
# GO Repo base repo
FROM alpine:latest
RUN apk --no-cache add ca-certificates curl
RUN mkdir /app
WORKDIR /app/
# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/main .
# Expose port 8000
EXPOSE 8000
# Run Executable
CMD ["./main"]
在這里,我們創(chuàng)建一個(gè)中間docker builder容器,將代碼復(fù)制到其中,在builder容器內(nèi)構(gòu)建代碼,然后將binary映像復(fù)制到實(shí)際的 docker。
這將有助于在最終容器中包含所有依賴項(xiàng),而且最終圖像的大小將非常小
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)