Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrink docker build context #1066

Merged

Conversation

MarcelWaldvogel
Copy link
Contributor

During make buildDockerImages, I noticed that 1.8GB (or GO 😉) have to be sent to the docker builder. This significantly reduces the context that has to be transferred.

@ggrossetie
Copy link
Member

Oh that's why, I didn't know that!
I found a good explanation:

The Docker client sends the entire "build context" to the Docker daemon. That build context (by default) is the entire directory the Dockerfile is in (...)

We should probably add a .dockerignore in each directory from where we build a Docker image?

And we might reduce the build context by building from a subdirectory when generating binaries with Docker.

Anyway, I'm glad to merge this pull request as is since it already improves the situation. Let me know if you think we should add additional improvements in this pull request or in follow-up pull requests?

@MarcelWaldvogel
Copy link
Contributor Author

Only the .dockerignore at the root of the current context is consulted, so, yes, for different contexts, different .dockerfiles are needed.

As you are creating many different contexts, limiting the inclusion of binaries might be useful. But it is also possible to create multiple images in a single docker build process (multiple FROM lines in a single Dockerfile). AFAIK, however, only one of the multiple builds, namely the last, can be easily made into a "public" image.

However, if there are just a few dozen megabytes sent to the Docker context, I typically do not care. Only what is used with COPY and friends ends up in the final image, everything else is only slowing down build time (and not that much, compared to the rest). But once I see the transfer counter several seconds, I try to reduce the context size…

@MarcelWaldvogel
Copy link
Contributor Author

BTW: If you think building for ARM might be a good idea, I do have experience creating multi-architecture docker images, e.g. in KNOT DNS.

@ggrossetie
Copy link
Member

However, if there are just a few dozen megabytes sent to the Docker context, I typically do not care. Only what is used with COPY and friends ends up in the final image, everything else is only slowing down build time (and not that much, compared to the rest). But once I see the transfer counter several seconds, I try to reduce the context size…

That sounds fair. Let's merge this pull request 👍🏻

BTW: If you think building for ARM might be a good idea, I do have experience creating multi-architecture docker images, e.g. in KNOT DNS.

There might be some interest, please create a new issue so we can evaluate if we want to support it or not.

@ggrossetie ggrossetie merged commit a22288b into yuzutech:main Jan 19, 2022
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