# golang环境编译 docker build -t dev.daymele.com:5000/ltadapt . FROM golang:latest as build ENV GO111MODULE on ENV GOPROXY=https://goproxy.io ENV GOPRIVATE=git.daymele.com WORKDIR / # 通过提前运行go mod download可以使用cache编译,避免每次编译都下载,加快编译速度 COPY go.mod go.mod COPY go.sum go.sum RUN go mod download ADD . / RUN GOOS=linux CGO_ENABLED=0 go build -o adapt -ldflags="-w -s" # 生成alpine部署容器 FROM alpine:latest #FROM scratch #scratch 需要下一语句安装ssl证书 #ADD https://curl.haxx.se/ca/cacert.pem /etc/ssl/certs/ # 时区处理(方法一:需要提前准备下两条,scratch和alpine都可以使用) # tar cfz zoneinfo.tar.gz /usr/share/zoneinfo # cp /usr/share/zoneinfo/PRC PRC ADD PRC /etc/localtime ADD zoneinfo.tar.gz / # 设置时区(方法二) #RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories # apk update && apk upgrade #RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ # && echo "Asia/Shanghai" > /etc/timezone \ # && apk del tzdata \ # && rm -rf /var/cache/apk/* # 健康检测 ADD ./hc.sh /root/healthcheck.sh HEALTHCHECK --start-period=60s --interval=30s --timeout=5s --retries=3 CMD /bin/ash /root/healthcheck.sh LABEL MAINTAINER="LIU Peng" WORKDIR "/" COPY --from=build /adapt /adapt ENTRYPOINT ["/adapt","-port","8012"] EXPOSE 8012 # docker image prune 删除悬虚镜像