-
Notifications
You must be signed in to change notification settings - Fork 234
/
Dockerfile
66 lines (51 loc) · 1.86 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Compile stage
FROM golang:1.21-alpine3.20 AS builder
# The latest alpine images don't have some tools like (`git` and `bash`).
# Adding git, bash and openssh to the image
RUN apk add --no-cache git make bash ca-certificates tzdata \
--repository http://mirrors.aliyun.com/alpine/v3.11/community \
--repository http://mirrors.aliyun.com/alpine/v3.11/main
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.8 && \
wget -qO/bin/grpc_health_probe \
https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
# 镜像设置必要的环境变量
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
GOPROXY="https://goproxy.cn,direct" \
TZ=Asia/Shanghai \
APP_ENV=docker
# 移动到工作目录
WORKDIR /go/src/github.com/go-eagle/eagle
# 复制项目中的 go.mod 和 go.sum文件并下载依赖信息
COPY go.mod .
COPY go.sum .
RUN go mod download
# 将代码复制到容器中
COPY . .
COPY config ./config
# Build the Go app
RUN make build
# 创建一个小镜像
# Final stage
FROM alpine:3.15
WORKDIR /bin
ENV APP_ENV local
# 从builder镜像中把 /build 拷贝到当前目录
COPY --from=builder /go/src/github.com/go-eagle/eagle/eagle /bin/eagle
COPY --from=builder /go/src/github.com/go-eagle/eagle/config /data/conf/eagle/config
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
RUN apk update \
&& apk add --no-cache curl jq \
&& rm -rf /var/cache/apk/* \
&& mkdir -p /data/logs/
# Expose port 8080 to the outside world
EXPOSE 8080
# EXPOSE 9090
# 需要运行的命令
CMD ["/bin/eagle", "-c", "/data/conf/eagle/config"]
# 1. build image: docker build -t eagle:v1.0.1 -f Dockerfile .
# 2. start: docker run --rm -it -p 8080:8080 eagle:v1
# 3. test: curl -i http://localhost:8080/health