...
Minimizing Container Image Size
Recommendation | Description |
---|---|
Choose a small base image | Base images are container images that do not have a parent. Container images usually have their own root filesystem with an operating system installed. Typically, you will create a new image using a base image that contains an operating system. Consider the following when selecting a base image:
|
Be mindful of where your Dockerfile is located (i.e. Understand the build context) | 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. |
Use multi-stage builds | 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. |
Don’t install unnecessary packages | Avoid installing extra or unnecessary packages. This will reduce complexity, dependencies, |
build times and image sizes. For example, don't include a text editor in a database image. | |
Minimize the number of layers |
To reduce the number of layers and the image size, don't use Example:
|