-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
30 lines (21 loc) · 864 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
# Using golang:1.21-alpine as the base image for the builder stage
FROM golang:1.21-alpine as builder
# Set the working directory inside the container to /app
WORKDIR /app
# Copy the go.mod file into the /app directory
COPY go.mod .
# Copy the main.go source file into the /app directory
COPY main.go .
# Compile the application to a binary called 'main'.
# CGO_ENABLED=0 disables CGO for static building. GOOS=linux ensures compatibility.
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
# Start a new stage from alpine:3.19 for a smaller, final image
FROM alpine:3.19
# Set the working directory in the container to /root/
WORKDIR /root/
# Copy the compiled 'main' binary from the builder stage to the /root/ directory
COPY --from=builder /app/main .
# Expose port 8080 for the application
EXPOSE 8080
# Command to run the compiled binary
CMD ["./main"]