alcex commited on
Commit
3d5bf4e
·
verified ·
1 Parent(s): 90525e7

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +8 -26
Dockerfile CHANGED
@@ -1,32 +1,14 @@
1
- FROM golang:1.20 AS builder
2
-
3
- # Set the Current Working Directory inside the container
4
  WORKDIR /app
5
-
6
- # Copy go.mod and go.sum files
7
- COPY go.mod .
8
- COPY go.sum .
9
-
10
- # Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
11
  RUN go mod download
12
-
13
- # Copy the source code into the container
14
  COPY . .
 
 
15
 
16
- # Build the Go app
17
- RUN go build -o main .
18
-
19
- # Start a new stage from scratch
20
  FROM alpine:latest
21
-
22
- # Set the Current Working Directory inside the container
23
- WORKDIR /root/
24
-
25
- # Copy the Pre-built binary file from the previous stage
26
- COPY --from=builder /app/main .
27
-
28
- # Expose port 8080 to the outside world
29
  EXPOSE 8080
30
-
31
- # Command to run the executable
32
- CMD ["./main"]
 
1
+ FROM golang:1.21-alpine AS builder
 
 
2
  WORKDIR /app
3
+ COPY go.mod go.sum ./
 
 
 
 
 
4
  RUN go mod download
 
 
5
  COPY . .
6
+ RUN CGO_ENABLED=0 GOOS=linux go build -o myapp .
7
+ RUN chmod +x myapp # 赋予执行权限
8
 
 
 
 
 
9
  FROM alpine:latest
10
+ WORKDIR /app
11
+ COPY --from=builder /app/myapp .
 
 
 
 
 
 
12
  EXPOSE 8080
13
+ ENV AUTH_TOKEN=your_auth_token_here
14
+ CMD ["./myapp"]