Skip to content

Commit

Permalink
optimized dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshjosh361 committed Oct 10, 2024
1 parent 74a22e5 commit b9c2d5c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions product-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
FROM golang:1.22.2
FROM golang:1.22.2-alpine AS builder

WORKDIR /app

COPY go.mod ./
COPY go.sum ./
RUN go mod download


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: Create a minimal image
FROM alpine:latest

# Set working directory for the final image
WORKDIR /root/

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


EXPOSE 8081

CMD ["./main"]

CMD ["./main"]

0 comments on commit b9c2d5c

Please sign in to comment.