-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerFile.dev
More file actions
34 lines (24 loc) · 787 Bytes
/
Copy pathDockerFile.dev
File metadata and controls
34 lines (24 loc) · 787 Bytes
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
# --- Stage 1: Build the binary ---
FROM golang:1.26-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy the package management files first to leverage Docker caching
COPY go.mod go.sum ./
RUN go mod download
# Copy the remaining application source code
COPY . .
# Build the binary
RUN GOOS=linux go build -o main .
# --- Stage 2: Final lightweight execution environment ---
FROM alpine:3.19
# Add a non-root user for security purposes
RUN adduser -D appuser
USER appuser
# Set working directory
WORKDIR /app
# Copy only the compiled binary from the builder stage
COPY --from=builder /app/main .
# Expose the port your application listens on (e.g., 8080)
EXPOSE 8080
# Run the binary - this will be override in docker compose
CMD ["./main"]