stuve-it-backend/Dockerfile

47 lines
1.2 KiB
Docker
Raw Permalink Normal View History

2023-11-20 15:32:32 +00:00
# Start from the official Go image to create a build artifact.
# This is the first stage of a multi-stage build.
FROM golang:1.22 as builder
2023-11-20 15:32:32 +00:00
# Set labels
LABEL maintainer="Valentin Kolb"
LABEL version="2.0"
2023-11-20 15:32:32 +00:00
# Set the working directory inside the container.
WORKDIR /build
# Copy go.mod and go.sum to download dependencies.
COPY go.mod .
# Download Go modules (dependencies).
RUN go mod download
# Copy the rest of the source code.
COPY . .
# https://stackoverflow.com/questions/36279253/go-compiled-binary-wont-run-in-an-alpine-docker-container-on-ubuntu-host
ENV CGO_ENABLED=0
# Build the Go app as a static binary.
# You might need to add tags or other build arguments depending on your application.
RUN go build -o pocketbase main/main.go
# Start from a smaller image to make the final image smaller.
FROM alpine:latest
# Set the working directory inside the container.
WORKDIR /app
# Copy the statically-linked binary from the builder stage.
COPY --from=builder /build/pocketbase .
# Copy html files
COPY ./html ./html
2023-11-20 15:32:32 +00:00
# Expose port 8090 to the outside world.
EXPOSE 8090
# Update Path
ENV PATH="/app:${PATH}"
# Command to run the executable.
CMD ["./pocketbase", "serve", "--http=0.0.0.0:8090", "--dir=/pb_data"]