General Guidelines | Comments | Disposition |
---|---|---|
When executing " Irrespective of where the Inadvertently including files that are not necessary for building an image results in a larger build context and larger image size. This can increase the time to build the image, time to pull and push it, and the container runtime size. | ||
2. Exclude with .dockerignoreExclude files not relevant to the build with a This file supports exclusion patterns similar to | ||
3.Use multi-stage buildsMulti-stage builds reduces the size of an image, without worrying about the number of intermediate layers and files. An image is built during the final stage of the build process. The number of image layers can be minimized by leveraging build cache. For a build that contains several layers, order them from the less frequently changed (re-use build cache) to the more frequently changed:
| ||
4. Don’t install unnecessary packagesAvoid installing extra or unnecessary packages. This will reduce complexity, dependencies, file sizes, and build times, Don't include a text editor in a database image. | ||
5. Decouple applicationsApply the principle of "separation of concerns." Each container should have only one concern. Decoupling applications into multiple containers makes it easier to reuse containers. | ||
6. Minimize the number of layersThe instructions Use multi-stage builds, to only copy the artifacts you need into the final image. Tools and debug information can be added to intermediate build stages without increasing the size of the final image. | ||
7. Sort multi-line argumentsTo minimize duplication of packages and make the list of packages much easier to update, sort multi-line arguments alphanumerically. | ||
8. Re-use the build cacheAs each instruction in the Dockerfile is examined, the builder looks for an existing image in its cache that can be reused, rather than creating a duplicate image.
Once the cache is invalidated, all subsequent | ||
Build File Instructions | Comments | Disposition |