Git Product home page Git Product logo

Comments (3)

finkr avatar finkr commented on July 18, 2024

Two possibilities:

  • Simple multistage image, using alpine as base image, includes apk and shell (21Mb)
  • Statically compiled with empty base image (scratch), in the spirit of distroless, (14Mb).

Simple multistage

FROM golang:alpine as build

WORKDIR /usr/src/app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .
RUN go build -v -o /usr/local/bin/pure-fa-om-exporter cmd/fa-om-exporter/main.go

FROM alpine
COPY --from=build  /usr/local/bin/pure-fa-om-exporter /usr/local/bin/pure-fa-om-exporter
EXPOSE 9490
ENTRYPOINT ["/usr/local/bin/pure-fa-om-exporter"]
CMD ["--host", "0.0.0.0", "--port", "9490"]
$ docker history pure-fa-om-exporter 
IMAGE                CREATED BY                                      SIZE      COMMENT
51d99b9251e5   /bin/sh -c #(nop) CMD ["--host" "0.0.0.0" "…   0B        
353a48112424   /bin/sh -c #(nop) ENTRYPOINT ["/usr/local/b…   0B        
d2a24d618855   /bin/sh -c #(nop) EXPOSE 9490                  0B        
1ca44db4f499   /bin/sh -c #(nop) COPY file:30dad3c48b73c1a1…   13.6MB    
042a816809aa   /bin/sh -c #(nop) CMD ["/bin/sh"]              0B        
<missing>      /bin/sh -c #(nop) ADD file:e4d600fc4c9c293ef…   7.05MB   

Statically compiled (14Mb)

Go-lang compilation options for static build are inspired by prometheus/node-exporter.

Some projects also provides container with a shell (typically busybox)

FROM golang:alpine as build

WORKDIR /usr/src/app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .
RUN CGO_ENABLED=1 go build -a -tags 'netgo osusergo static_build' -v -o /usr/local/bin/pure-fa-om-exporter cmd/fa-om-exporter/main.go

FROM scratch
#FROM busybox:musl
COPY --from=build  /usr/local/bin/pure-fa-om-exporter /pure-fa-om-exporter
EXPOSE 9490
ENTRYPOINT ["/pure-fa-om-exporter"]
CMD ["--host", "0.0.0.0", "--port", "9490"]
$ docker history d6274a0aaee5
IMAGE          CREATED BY                                      SIZE      COMMENT
d6274a0aaee5   /bin/sh -c #(nop) CMD ["--host" "0.0.0.0" "…   0B        
7a04a959cb79   /bin/sh -c #(nop) ENTRYPOINT ["/pure-fa-om-…   0B        
3bb9c2a0527f   /bin/sh -c #(nop) EXPOSE 9490                  0B        
03bae96ab57e   /bin/sh -c #(nop) COPY file:4774cc7a4b571ef1…   13.5MB    

from pure-fa-openmetrics-exporter.

genegr avatar genegr commented on July 18, 2024

Thanks for noticing this! It is now fixed in v1.0.4.

from pure-fa-openmetrics-exporter.

finkr avatar finkr commented on July 18, 2024

fixed in 07f77ff (Thanks to @genegr )

from pure-fa-openmetrics-exporter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.