DEV Community

Vladimir Gordeev 🇷🇺
Vladimir Gordeev 🇷🇺

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

3

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.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay