面包店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Dockerfile 1.3 KiB

10 months ago
9 months ago
10 months ago
8 months ago
10 months ago
9 months ago
10 months ago
9 months ago
10 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # 多重构建,减少镜像大小
  2. # 构建:使用golang:1.15版本
  3. FROM golang:1.18 as build
  4. # 容器环境变量添加,会覆盖默认的变量值
  5. ENV GO111MODULE=on
  6. ENV GOPROXY=https://goproxy.cn,direct
  7. ENV TZ="Asia/Shanghai"
  8. # 设置工作区
  9. WORKDIR /go/release
  10. # 把全部文件添加到/go/release目录
  11. ADD . .
  12. # 编译:把main.go编译成可执行的二进制文件,命名为zyos
  13. RUN GOOS=linux CGO_ENABLED=0 GOARCH=amd64 go build -tags netgo -ldflags="-s -w" -installsuffix cgo -o zyos main.go
  14. FROM ubuntu:xenial as prod
  15. LABEL maintainer="wuhanqin"
  16. ENV TZ="Asia/Shanghai"
  17. COPY static/html static/html
  18. COPY static/template static/template
  19. # 时区纠正
  20. RUN rm -f /etc/localtime \
  21. && ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  22. && echo "Asia/Shanghai" > /etc/timezone
  23. # 优化内核参数
  24. #RUN sysctl -w net.ipv4.tcp_fin_timeout=15
  25. #RUN sysctl -w net.ipv4.tcp_tw_recycle=1
  26. #RUN sysctl -w net.ipv4.ip_local_port_range=1024 65535
  27. #RUN sysctl -p
  28. # 在build阶段复制可执行的go二进制文件app
  29. COPY --from=build /go/release/zyos ./zyos
  30. COPY --from=build /go/release/etc/cfg.yml /var/zyos/cfg.yml
  31. # 启动服务
  32. #CMD ["./zyos","-c","/var/zyos/cfg.yml"]
  33. CMD ["bash","-c","sysctl -w net.ipv4.ip_local_port_range='1024 65535' && sysctl -p && ./zyos -c /var/zyos/cfg.yml"]