Files
my_website/Dockerfile
2025-11-17 06:29:51 +07:00

41 lines
968 B
Docker

# ------------------------------------------------------
# 1. Build Stage
# ------------------------------------------------------
FROM golang:1.25-alpine AS builder
# Install necessary build tools for SQLite (CGO)
RUN apk add --no-cache gcc musl-dev sqlite-dev
WORKDIR /app
# Cache dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy source files
COPY . .
# Build with CGO enabled for SQLite
RUN CGO_ENABLED=1 GOOS=linux go build -o server
# ------------------------------------------------------
# 2. Runtime Stage
# ------------------------------------------------------
FROM alpine:3.20
# Install SQLite (if your app interacts directly with .db file)
RUN apk add --no-cache sqlite
WORKDIR /app
# Copy binary and required files
COPY --from=builder /app/server .
COPY --from=builder /app/css ./css
COPY --from=builder /app/views ./views
COPY --from=builder /app/my_website.db ./
COPY --from=builder /app/data ./data
EXPOSE 8080
CMD ["./server"]