From 9cd5c4e70803b345ae61302d0ac419de38f41aad Mon Sep 17 00:00:00 2001 From: dengbiao Date: Thu, 5 Dec 2024 17:14:04 +0800 Subject: [PATCH] update --- Dockerfile-prd | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Dockerfile-prd diff --git a/Dockerfile-prd b/Dockerfile-prd new file mode 100644 index 0000000..ca8a58f --- /dev/null +++ b/Dockerfile-prd @@ -0,0 +1,38 @@ +# 多重构建,减少镜像大小 +# 构建:使用golang:1.18版本(直接使用自己从香港下载回来的镜像版本,提高打包速度) +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编译成可执行的二进制文件,命名为egg +RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o egg 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 +COPY static/bat static/bat +# 时区纠正 +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/egg ./egg + +COPY --from=build /go/release/etc/cfg.yml /var/egg/cfg.yml + +# 启动服务 +CMD ["bash","-c","sysctl -w net.ipv4.tcp_tw_reuse=1 && sysctl -w net.ipv4.tcp_fin_timeout=10 && sysctl -w net.ipv4.ip_local_port_range='1024 65535' && sysctl -p && ./egg -c /var/egg/cfg.yml"] + +