-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
35 lines (25 loc) · 923 Bytes
/
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
# Step 1: Use the official Golang image to build the app
# This uses the latest Go version
FROM golang:1.23.1-alpine3.20 AS builder
# Step 2: Set the working directory inside the container
WORKDIR /app
# Step 3: Copy the go.mod and go.sum files to the working directory
COPY go.mod go.sum ./
# Step 4: Download all Go module dependencies
# Dependencies will be cached if the go.mod and go.sum files haven't changed
RUN go mod download
# Step 5: Copy the rest of the application code to the container
COPY . .
# Step 6: Build the Go app
RUN go build -o main .
# Step 7: Use a minimal base image for running the app
FROM alpine:latest
# Step 8: Set the working directory for the minimal base image
WORKDIR /app
# Step 9: Copy the Go app from the builder stage
COPY --from=builder /app/main .
COPY config.yaml .
# Step 10: Expose the port the app runs on
EXPOSE 3333
# Step 11: Command to run the app
CMD ["./main"]