-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (27 loc) · 1.03 KB
/
Dockerfile
File metadata and controls
39 lines (27 loc) · 1.03 KB
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
# Stage 1: Build the Go application
FROM golang:1.22-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy go.mod and go.sum files to leverage Docker's layer caching
COPY go.mod go.sum ./
# Download Go modules
RUN go mod download
# Copy the rest of the application source code
COPY . .
# Build the Go application
# CGO_ENABLED=0 disables CGO, creating a statically linked binary
# GOOS=linux ensures the binary is built for a Linux environment
# -o specifies the output file name
RUN CGO_ENABLED=0 GOOS=linux go build -o PrintAndGo .
# Stage 2: Create the final, minimal image
FROM alpine:latest
# Set the working directory in the final image
WORKDIR /app
# Install necessary runtime dependencies (e.g., CA certificates for HTTPS)
RUN apk --no-cache add ca-certificates tzdata
# Copy the built binary from the builder stage
COPY --from=builder /app/PrintAndGo .
# Expose the port your application listens on (if applicable)
EXPOSE 5001
# Set the entrypoint command to run the application
#CMD ["/app/myapp "]