DEV Community

Vladimir Gordeev 🇷🇺
Vladimir Gordeev 🇷🇺

Posted on • Updated on • Originally published at vladimir-vg.me

Why your docker builds are slow?

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.

Top comments (0)