...

/

Reducing the Size of the Image Using Multistage Builds

Reducing the Size of the Image Using Multistage Builds

Learn to reduce the size of the final Docker image for the app.

So far, we have been building our Docker image by:

  • Using a standard Docker Go image as a base.

  • Downloading dependencies in it.

  • Building an executable.

  • Packaging all the above into a new Docker image.

That's a lot of packing! If we check the final size of this image using docker images, we'll find it to be about 1GB. And this is the size of just one image. Ideally, we would want to keep multiple versions of this image and there may be many apps. This would increase the storage required multifold. Think of the amount of storage and, inevitably, the money it's going to cost!

However, as always, Docker provides a solution to this in the form of multi-stage builds.

Multistage builds

...