# 多重构建,减少镜像大小 # 构建:使用golang:1.18版本 FROM registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/golang:1.19 as build # 容器环境变量添加,会覆盖默认的变量值 ENV GO111MODULE=on ENV GOPROXY=https://goproxy.cn,direct ENV TZ="Asia/Shanghai" # 设置工作区 WORKDIR /go/release # 把全部文件添加到/go/release目录 ADD . . # 编译:把main.go编译成可执行的二进制文件,命名为egg_im RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -o egg-im cmd/connect/main.go FROM ubuntu:xenial as prod LABEL maintainer="dengbiao" # 时区纠正 ENV TZ="Asia/Shanghai" RUN rm -f /etc/localtime \ && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \ && echo $TZ > /etc/timezone # 在build阶段复制可执行的go二进制文件app COPY --from=build /go/release/egg-im ./egg-im # 启动服务 # 优化内核参数 #RUN sysctl -w net.ipv4.tcp_fin_timeout=15 #RUN sysctl -w net.ipv4.tcp_tw_recycle=1 #RUN sysctl -w net.ipv4.ip_local_port_range=1024 65535 #RUN sysctl -p #CMD ["bash","-c","sysctl -w net.ipv4.tcp_timestamps=1 && sysctl -w net.ipv4.tcp_tw_reuse=1 && sysctl -w net.ipv4.tcp_tw_timeout=10 && sysctl -w net.ipv4.tcp_fin_timeout=10 && sysctl -w net.ipv4.ip_local_port_range='1024 65535' && ./egg-im"] CMD ["./egg-im"]