Add basic Dockerfile
This commit is contained in:
37
Dockerfile
Normal file
37
Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
# Use Go 1.25.6 or newer
|
||||
FROM golang:1.25.6-alpine AS builder
|
||||
|
||||
# Enable Go modules
|
||||
ENV GO111MODULE=on
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Install git (for go get) and build tools
|
||||
RUN apk add --no-cache git
|
||||
|
||||
# Copy go.mod and go.sum first for better cache
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the rest of the source code
|
||||
COPY . .
|
||||
|
||||
# Build the Go app
|
||||
RUN go build -o app .
|
||||
|
||||
# Stage 2: Create a minimal runtime image
|
||||
FROM alpine:latest
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /root/
|
||||
|
||||
# Copy binary and .env file from builder
|
||||
COPY --from=builder /app/app .
|
||||
COPY .env .
|
||||
|
||||
# Expose the port (optional, for documentation)
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the binary
|
||||
CMD ["./app"]
|
||||
Reference in New Issue
Block a user