Minimizing the size of Docker images using multi-stage builds

  1. A multi-stage build version of hello world
  2. Single-stage build of dummyFoam
  3. Analyzing library dependencies
  4. Multi-stage build of dummyFoam
  5. Summary

When compiling a new high-level application or utility that will be shipped as a container, ideally, you want to start from a base image that comes as close as possible to the build-environment you need to compile your application. For example, if you’re going to create and build a custom OpenFOAMĀ® solver, it makes perfect sense to start with the OpenFOAM-plus Docker image as a base (learn more about the Docker-based OpenFOAM workflow). You may install additional third-party libraries, copy your sources to the image, and compile. This workflow is really convenient since it allows, for example, to compile your application against a variety of OpenFOAM versions or flavors at lighting speed while keeping all dependencies nicely separated. One disadvantage, however, is the quickly increasing storage demand since every newly created image contains both the build-environment and the application. Moreover, sending the image over the network will take longer and cause significantly more traffic. Of course, there is an established way to overcome these disadvantages called multi-stage builds, and this article tells you how to apply it to OpenFOAM applications.

Continue reading “Minimizing the size of Docker images using multi-stage builds”