Added Golang use case
This commit is contained in:
1 parent
cb447ed7c0
commit
52d0eb21d2
6 files changed
+192
No files matched your search
@@ -0,0 +1,30 @@
|
||||
# Use the official Golang image to create a build environment.
|
||||
FROM golang:1.21-alpine AS builder
|
||||
|
||||
# Set the working directory inside the container.
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go mod and sum files.
|
||||
COPY go.mod go.sum ./
|
||||
|
||||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed.
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source code into the container's workspace.
|
||||
COPY . .
|
||||
|
||||
# Build the command inside the container.
|
||||
# Compile the binary statically, including all dependencies.
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o myapp .
|
||||
|
||||
# Use a Docker multi-stage build to create a lean production image.
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy the binary to the production image from the builder stage.
|
||||
COPY --from=builder /app/myapp .
|
||||
|
||||
EXPOSE 5000
|
||||
|
||||
CMD ["./myapp"]
|
||||
Reference in new issue
Block a user