-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
40 lines (34 loc) · 1.31 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
# Build the manager binary
FROM golang:1.18.7-alpine3.15 as builder
WORKDIR /app
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# 坑:
# 报错 go mod download: google.golang.org/[email protected]: read tcp 172.17.0.3:60862->14.204.51.154:443: read: connection reset by peer
# The command '/bin/sh -c go mod download' returned a non-zero code: 1
# make: *** [docker-build] 错误 1
ENV GOPROXY=https://goproxy.cn,direct
ENV GO111MODULE=on
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
# # 需要把该放入的都copy进去,如果报出 package xxxxx is not in GOROOT => 就是这个问题。
COPY main.go main.go
COPY pkg/ pkg/
COPY app.yaml app.yaml
COPY global_config/ global_config/
RUN chmod 777 ./app.yaml
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o mydbconfigoperator main.go
FROM alpine:3.12
WORKDIR /app
# 需要的文件需要复制过来
USER root
COPY --from=builder --chown=root:root /app/mydbconfigoperator .
COPY --from=builder --chown=root:root /app/app.yaml .
COPY --from=builder --chown=root:root /app/global_config global_config/
RUN chmod 777 /app/app.yaml
RUN chmod 777 global_config/
ENTRYPOINT ["./mydbconfigoperator"]