$ cat ./deployments/docker-compose.md
Docker Compose
For simple deployments or local development, Docker Compose is a great choice. It allows you to define your application's services in a single YAML file.
Dockerfile
First, we need a Dockerfile to build our Go application.
# Build Stage
FROM golang:1.25-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o main .
# Run Stage
FROM alpine:latest
WORKDIR /root/
COPY --from=builder /app/main .
COPY --from=builder /app/static ./static
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/content ./content
EXPOSE 8080
CMD ["./main"]
docker-compose.yml
Then, define the service in docker-compose.yml.
version: '3.8'
services:
web:
build: .
ports:
- "8080:8080"
restart: always
To run it:
docker-compose up -d --build