What Is the Builder Pattern?
The builder pattern is a method used to create optimally sized Docker images. It uses two Docker images and selectively copies essential artifacts from one to the other. The first Docker image is known as the build image
and is used as the build environment to build the executables from the source code. This Docker image contains compilers, build tools, and development dependencies required during the build process.
The second Docker image is known as the runtime image
and is used as the runtime environment to run the executables created by the first Docker container. This Docker image contains only the executables, the dependencies, and the runtime tools. A shell script is used to copy the artifacts using the docker container cp
command.
The entire process of building the image using the builder pattern consists of the following steps:
- Create the
Build
Docker image. - Create a container from the
Build
Docker image. - Copy the artifacts...