optimize Dockerfile using scratch image
This commit is contained in:
parent
346ad3b990
commit
7fb0ebff20
1 changed files with 11 additions and 8 deletions
19
Dockerfile
19
Dockerfile
|
@ -1,13 +1,16 @@
|
||||||
FROM golang:1.16
|
############################
|
||||||
|
# STEP 1 build executable binary
|
||||||
|
############################
|
||||||
|
FROM golang:1.16 AS builder
|
||||||
RUN mkdir -p /weather-api
|
RUN mkdir -p /weather-api
|
||||||
|
|
||||||
WORKDIR /weather-api
|
WORKDIR /weather-api
|
||||||
|
|
||||||
ADD . /weather-api
|
ADD . /weather-api
|
||||||
|
RUN env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags "$(govvv -flags)" -o app
|
||||||
RUN go build ./main.go
|
|
||||||
|
|
||||||
|
# STEP 2 build a small image
|
||||||
|
############################
|
||||||
|
FROM scratch
|
||||||
|
COPY --from=builder /weather-api/app /app
|
||||||
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
EXPOSE 10000
|
EXPOSE 10000
|
||||||
|
ENTRYPOINT ["/app"]
|
||||||
CMD ["./main"]
|
|
Loading…
Add table
Reference in a new issue