When I build images with docker build
the output contains the context size, e.g.:
Sending build context to Docker daemon 1.315GB
[...]
Successfully built a9ec4d33e12e
Does this size affect the resulting image size? Should I seek to reduce it?
When I build images with docker build
the output contains the context size, e.g.:
Sending build context to Docker daemon 1.315GB
[...]
Successfully built a9ec4d33e12e
Does this size affect the resulting image size? Should I seek to reduce it?
Does this size affect the resulting image size?
No
Should I seek to reduce it?
Yes. It saves time building the image.
source:
https://medium.com/better-programming/docker-tips-about-the-build-context-dbc76505e178
When you run docker build
it sends all of the files in the Dockerfile
's directory and all subdirectories over to the Docker daemon. It does this under the assumption that your Dockerfile
is probably going to reference all of those files, but note that it doesn't check your Dockerfile
to figure out what files to send. It simply sends everything.
There are a couple ways to reduce the build context size:
Put your Dockerfile
in its own directory with only the files it needs. For instance, instead of having a Dockerfile
at the top level of your project, put it in its own subdirectory.
Write a .dockerignore
file that lists files to exclude from the build context. When you can't move files out of the way this is the next best thing.
Does this size affect the resulting image size?
Yes and no. An overly large build context won't increase the image size. Extra files in the build context that aren't used by the Dockerfile
are simply thrown away.
However, if you use .dockerignore
to ignore files that the Dockerfile
does use that can reduce the image size (and potentially break it). Ignoring files will cause COPY . /app
to copy fewer files, for instance.
Should I seek to reduce it?
Yes. It'll speed up the build process.
The build context can in some cases impact the size of the image, yes.
If you do:
COPY . /app
Then everything in the context will be copied to /app
in the image.
If you're only copying explicit subsets of the context, e.g. COPY mydir/ app/
, then the context size won't impact image size, only the contents of mydir
will impact image size.
You should create a .dockerignore
that omits files you don't care about.
Does this size affect the resulting image size?
No
Should I seek to reduce it?
Yes. It saves time building the image.
source:
https://medium.com/better-programming/docker-tips-about-the-build-context-dbc76505e178
© 2022 - 2024 — McMap. All rights reserved.