Skip to content

Commit

Permalink
multi-stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshjosh361 committed Oct 10, 2024
1 parent 5aab6da commit 07dc7fd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions order-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
FROM golang:1.22.2
# First stage: Build the Go binary
FROM golang:1.22.2-alpine AS builder

WORKDIR /app

# Copy go.mod and go.sum to cache dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download

# Copy the rest of the application files
COPY . .

RUN go build -o main .
# Build the Go app as a statically linked binary
RUN CGO_ENABLED=0 GOOS=linux go build -o main .

# Second stage: Minimal runtime image
FROM alpine:latest

WORKDIR /root/

# Copy the Go binary from the builder stage
COPY --from=builder /app/main .

# Expose port 8083
EXPOSE 8083

CMD ["./main"]
# Run the Go binary
CMD ["./main"]

0 comments on commit 07dc7fd

Please sign in to comment.