ZhangZhihui's Blog  

 

FROM golang:alpine AS builder

# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git

RUN mkdir $GOPATH/src/server
ADD ./stats.go $GOPATH/src/server
ADD ./handlers.go $GOPATH/src/server
WORKDIR $GOPATH/src/server
RUN go env -w GOPROXY=https://goproxy.io,direct
RUN go mod init
RUN go mod tidy
RUN mkdir /pro
RUN go build -o /pro/server stats.go handlers.go

FROM alpine:latest

WORKDIR /pro
COPY --from=builder /pro/server .
EXPOSE 1234
CMD ["/pro/server"]

 

zzh@ZZHPC:/zdata/Github/mastering-go-expertise/stats_web/server$ docker build -f Dockerfile -t stats_server .

The build is successful.

posted on 2024-06-25 21:53  ZhangZhihuiAAA  阅读(5)  评论(0编辑  收藏  举报