Skip to content

Commit

Permalink
Reduce Docker image size (#24)
Browse files Browse the repository at this point in the history
By using Alpine instead of Ubuntu, the resulting image is around
110 MB smaller:

    $ docker images
    REPOSITORY       TAG      CREATED         SIZE
    unms-exporter    alpine   3 seconds ago   20MB
    unms-exporter    ubuntu   5 minutes ago   132MB

We could save 5 MB more by using `FROM scratch` instead of Alpine,
but then handling of timezone and CA certificate files becomes a
hassle.
dmke authored Apr 11, 2022
1 parent 9af7229 commit 9c2efb6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM golang:1.18 AS build
FROM golang:1.18-alpine AS build

WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download

ENV CGO_ENABLED=0

COPY . ./
RUN go build -o unms-exporter main.go
RUN go build -ldflags="-s -w" -trimpath -o unms-exporter main.go

FROM ubuntu:20.04
FROM alpine

RUN apt-get -q update && apt-get -yq install ca-certificates
RUN apk add --no-cache tzdata ca-certificates
COPY --from=build /src/unms-exporter /usr/local/bin/

CMD ["/usr/local/bin/unms-exporter"]

0 comments on commit 9c2efb6

Please sign in to comment.