prevent rebuilding whole docker container everytime? improving speed prevent rebuilding whole docker container everytime? improving speed docker docker

prevent rebuilding whole docker container everytime? improving speed


You can improve your build speed by:

  • Install all of your requirement as early as possible.
  • Combine all apt-get/yum into a single command, after that clean up the apt/yum cache. It can decrease your image size.

Sample:

RUN \  apt-get -y update && \  apt-get -y install curl build-essential nginx && \  apt-get clean && \  rm -rf /var/lib/apt/lists/*
  • Put ADD/COPY as late as possible, because it will invalidate the Docker image cache.
  • Avoid put long-running task (e.g: apt-get, download large file, etc.) after ADD/COPY file or directory that is often changed.

Docker take a "snapshot" for each your command. So, when you build a new image from same state (no Dockerfile/file/directory change), it should be fast.

Comment/uncomment Dockerfile in order to reduce apt-get install time might not help you, because it will invalidate your Docker cache.