boxes-api/Dockerfile

39 lines
942 B
Docker

# Stage 1: Build the Go binary
FROM golang:1.17-alpine AS builder
# Install build tools and SQLite development libraries
RUN apk add --no-cache gcc musl-dev sqlite-dev
# Set the working directory inside the container
WORKDIR /app
# Copy the Go modules files and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the application source code
COPY . .
# Build the Go application
RUN go build -o boxes-api
# Stage 2: Create a minimal image with the Go binary
FROM alpine:latest
# Install necessary runtime dependencies
RUN apk add --no-cache ca-certificates
# Set the working directory inside the container
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /app/boxes-api .
# Copy any other necessary files (e.g., configuration files)
# COPY --from=builder /app/config.yaml .
# Expose the port your app listens on
EXPOSE 8080
# Command to run the executable
CMD ["./boxes-api"]