Use multi-stage builds

This commit is contained in:
Fuxin Hao
2017-12-21 14:22:56 +08:00
committed by shengxiang
parent 876b8cffc4
commit bd7666b3e6

View File

@@ -1,7 +1,13 @@
FROM golang:latest
RUN mkdir /app
WORKDIR /app
ENV SRC_DIR=/go/src/github.com/codeskyblue/gohttpserver
ADD . $SRC_DIR
RUN cd $SRC_DIR; go build; cp gohttpserver /app/
ENTRYPOINT ["/app/gohttpserver"]
FROM golang:1.9 AS build
WORKDIR /go/src/github.com/codeskyblue/gohttpserver
ADD . /go/src/github.com/codeskyblue/gohttpserver/
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gohttpserver .
FROM alpine:3.6
WORKDIR /app
RUN mkdir -p /app/public
VOLUME /app/public
ADD res ./res
COPY --from=build /go/src/github.com/codeskyblue/gohttpserver/gohttpserver .
EXPOSE 8000
CMD ["/app/gohttpserver", "--root=/app/public"]