Codementor Events

Docker image build cache

Published Jun 20, 2018

The important thing when working with #docker is to write Dockerfile instructions in the right order. It may speed up the build significantly.

Every instruction in #Dockerfile is similar to a commit in git branch. If you change something in the middle, everything that follows after should be executed again (rebased in git terms). Everything that was before change can be reused.

All files that you add using COPY or ADD are considered as dependencies for everything that runs after.

Hence two rules to speedup your image builds:

  • what changes rarely should be executed first
  • avoid using 'ADD .' it makes everything depend on everything

Add Gemfile, rebar.config, mix.exs or any other file where your dependencies specified. Install dependencies, compile them. And only after that add your app source code.

This one of my posts I previously published on FB.

Discover and read more posts from Vladimir Gordeev
get started
post commentsBe the first to share your opinion
Show more replies