# 多重构建,减少镜像大小 # 构建:使用golang:1.15版本 FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.18.4 as build # 容器环境变量添加,会覆盖默认的变量值 ENV GO111MODULE=on ENV GOPROXY=https://goproxy.cn,direct ENV TZ="Asia/Shanghai" ENV PHONE_DATA_DIR="./static/bat" # 设置工作区 WORKDIR /go/release # 把全部文件添加到/go/release目录 ADD . . # 编译:把main.go编译成可执行的二进制文件,命名为zyos RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zyos_order_task cmd/task/main.go FROM ubuntu:xenial as prod LABEL maintainer="zengzhengrong" ENV TZ="Asia/Shanghai" ENV PHONE_DATA_DIR="./static/bat" COPY static/html static/html # 时区纠正 RUN rm -f /etc/localtime \ && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ && echo "Asia/Shanghai" > /etc/timezone # 在build阶段复制可执行的go二进制文件app COPY --from=build /go/release/community_team_task ./community_team_task COPY --from=build /go/release/etc/task.yml /var/zyos/task.yml # 启动服务 CMD ["./zyos_order_task","-c","/var/zyos/task.yml"]