complicate docker file to reduce size of build - #2
Conversation
| ADD go.mod ./ | ||
| RUN go mod download |
There was a problem hiding this comment.
you don't need to do this I don't think go build on line 7 does it already?
| ADD go.mod ./ | ||
| RUN go mod download | ||
| ADD . . | ||
| RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o transfermeit . |
There was a problem hiding this comment.
if you change to -o /transfermeit you can make the COPY command a lot smaller bellow:
COPY --from=builder /transfermeit /transfermeit
There was a problem hiding this comment.
Also why not just ?
RUN go build -o /transfermeit .
There was a problem hiding this comment.
From : https://rollout.io/blog/building-minimal-docker-containers-for-go-applications/
Huh? What does that mean? Took me a while to figure it out, but our Go binary is looking for libraries on the operating system it’s running in. We compiled our app, but it still is dynamically linked to the libraries it needs to run (i.e., all the C libraries it binds to). Unfortunately, scratch is empty, so there are no libraries and no loadpath for it to look in. What we have to do is modify our build script to statically compile our app with all libraries built in:
| @@ -2,11 +2,11 @@ FROM golang:1.14 as builder | |||
|
|
|||
| WORKDIR / | |||
| ADD go.mod ./ | |||
There was a problem hiding this comment.
Can you get rid of this line too :)
Act on review feedback
No description provided.