docker build
This commit is contained in:
24
dockerfile
24
dockerfile
@@ -1,14 +1,30 @@
|
||||
# Step 1: Build the Go binary
|
||||
# Step 1: Build the Go binary in a separate stage
|
||||
FROM golang:1.23 AS builder
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy the Go module files
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the application code
|
||||
COPY . .
|
||||
|
||||
# Build the Go binary with static linking for Linux
|
||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /server src/main.go
|
||||
|
||||
|
||||
FROM scratch
|
||||
|
||||
# Set the current working directory inside the container
|
||||
WORKDIR /app
|
||||
|
||||
# Copy go.mod and go.sum files
|
||||
COPY server ./
|
||||
COPY . .
|
||||
COPY --from=builder server ./
|
||||
|
||||
# Command to run the executable
|
||||
CMD ["./server"]
|
||||
|
||||
# Expose the port on which the Go server will run
|
||||
EXPOSE 80
|
||||
EXPOSE 54321
|
||||
Reference in New Issue
Block a user