Skip to content

complicate docker file to reduce size of build - #2

Open
pitabwire wants to merge 3 commits into
maxisme:masterfrom
pitabwire:master
Open

complicate docker file to reduce size of build#2
pitabwire wants to merge 3 commits into
maxisme:masterfrom
pitabwire:master

Conversation

@pitabwire

Copy link
Copy Markdown

No description provided.

Comment thread Dockerfile Outdated
Comment on lines +4 to +5
ADD go.mod ./
RUN go mod download

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to do this I don't think go build on line 7 does it already?

Comment thread Dockerfile Outdated
ADD go.mod ./
RUN go mod download
ADD . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o transfermeit .

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you change to -o /transfermeit you can make the COPY command a lot smaller bellow:

COPY  --from=builder /transfermeit /transfermeit

@maxisme maxisme Jul 13, 2020

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why not just ?

RUN go build -o /transfermeit .

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Comment thread Dockerfile Outdated
@@ -2,11 +2,11 @@ FROM golang:1.14 as builder

WORKDIR /
ADD go.mod ./

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get rid of this line too :)

Act on review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants