-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
44 lines (32 loc) · 1.12 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#母镜像
FROM golang:latest as build
#维护者信息
MAINTAINER keke
ENV GOPROXY https://goproxy.io/
# go module开启
ENV GO111MODULE on
WORKDIR /go/cache
# 添加go mod
ADD go.mod .
ADD go.sum .
# 构建缓存包含了该项所有的依赖起到加速构建的作用
RUN go mod download
#工作目录
WORKDIR /go/release
#将文件复制到镜像中
ADD . .
# ldflags中-s: 省略符号表和调试信息,-w: 省略DWARF符号表
RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o spike .
# scratch空的基础镜像,最小的基础镜像
# busybox带一些常用的工具,方便调试, 以及它的一些扩展busybox:glibc
# alpine另一个常用的基础镜像,带包管理功能,方便下载其它依赖的包
FROM scratch as prod
COPY --from=build /go/release/spike /
# 配置镜像的时间区
COPY --from=build /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 配置镜像的证书
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# 将构建的可执行文件复制到新镜像中
COPY --from=build /go/release/spike /
EXPOSE 8080
CMD ["/spike"]