How to build smaller Docker images

When you’re building a Docker image it’s important to keep the size under control. Having small images means ensuring faster deployment and transfers.

Wish I had found this post before I started playing with Docker, as it is packed with solid advice which I found out “along the way” myself.

In short:

  1. Find the right balance with the cache layers
  2. Use .dockerignore files
  3. Use the multi-stage builds feature
  4. Choose the right base image

Especially number 3 was an eye opener to me when I first discovered it. Basically it boils down to this: Don’t do an npm install/composer install/npm build directly in your “main” image, but do it in a separate container and afterwards copy its results into your main image.

How to build a smaller Docker image →

Join the Conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.