Dockerfile 996 B

12345678910111213141516171819202122232425262728293031323334
  1. FROM golang:1.18-alpine3.16 AS builder
  2. RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
  3. ARG APP_RELATIVE_PATH
  4. COPY . /data/app
  5. WORKDIR /data/app
  6. RUN rm -rf /data/app/bin/
  7. RUN export GOPROXY=https://goproxy.cn,direct && go mod tidy && go build -ldflags="-s -w" -o ./bin/server ${APP_RELATIVE_PATH}
  8. RUN mv config /data/app/bin/
  9. FROM alpine:3.16
  10. RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
  11. # alpine
  12. # 设置时区为上海
  13. RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  14. && echo "Asia/Shanghai" > /etc/timezone \
  15. && apk del tzdata
  16. ARG APP_ENV
  17. ENV APP_ENV=${APP_ENV}
  18. WORKDIR /data/app
  19. COPY --from=builder /data/app/bin /data/app
  20. EXPOSE 8000
  21. ENTRYPOINT [ "./server" ]
  22. #docker build -t 1.1.1.1:5000/demo-api:v1 --build-arg APP_CONF=config/prod.yml --build-arg APP_RELATIVE_PATH=./app/demo-api .
  23. #docker run -it --rm --entrypoint=ash 1.1.1.1:5000/demo-api:v1