Containerizing and Deploying the App

Let’s deploy the application on the Raspberry Pi as a container. First, create a container image for this application by writing a Dockerfile using the multi-stage approach you used in Containing and Deploying the Exporter:

 FROM docker.io/golang:1.22 AS builder
 RUN mkdir /app
 WORKDIR /app
 COPY . /app
 RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \
  -ldflags="-s -w" \
  -o lightweather \
  lightingweather.go config.go
 
 FROM docker.io/alpine:latest
 RUN mkdir /app && adduser -h /app -D lightweather
 WORKDIR /app
 COPY --chown=lightweather --from=builder /app/lightweather .
 EXPOSE 3040
 ENTRYPOINT ["/app/lightweather"]

The content of this Dockerfile is almost the same ...

Get Automate Your Home Using Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.