User:Arzano/Towards a slim Gentoo container image

This page describes how to get slim Gentoo based container images.

Current Image
Currently is used as base image. Furthermore, is used to copy the full ebuild tree into the container. This way it is possible to install packages.

Consequently, a typical Dockerfile currently looks like this:

Where this falls short
Unfortunately this results in rather large images, as
 * the image contains dependencies that are only needed during the build and not needed at runtime, and
 * the image contains dependencies that are neither needed during build nor at runtime (as they are included in the stage3 base image)

New Image
To solve the problems of the current approach:
 * a multi stage build is used to exclude the dependencies that are only needed during the build
 * a slim Stage 1 base image is used to exclude dependencies that are neither needed during build nor at runtime

Multi Stage Build
A multi stage build is used to build the application / static contents and copy only the required artifacts into the image. The multistage Dockerfile looks like this:

Stage 1 image
Catalyst can be used to create a stage1 tarball. The profile will be modified to: Afterwards the Stage 1 image can be created the same way as the Stage 3 image is currently created. This way, a slim base image is created.
 * exclude as many non-essential packages as possible, and
 * add further packages which are needed at runtime (as ruby for instance)

Comparison
As for the packages.g.o image, it turns out that the new image is 15 times smaller than the current image: