title: Gitlab CI: How to avoid rebuilding of images on each commit
body: <p>I'm using Gitlab CI to store and deploy docker images but I got a big issue. Gitlab CI is rebuilding all images on every commit.</p>
  
  <p>The first step is to build my common image which takes around 8 minutes. Currently I only modify child images but the common image is still rebuild on every commit.</p>
  
  <p>Thus the build is a waste of time because the push won't have an effect as the image is already inside the Gitlab repository.</p>
  
  <p>How to avoid the rebuild of images when it's already inside your Gitlab repository?</p>
  
  <p>Below gitlab-ci.yml</p>
  
  <pre><code>build:
     tags:
         - docker_ci_build
     services:
         - docker:dind
     script:
         - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
         - &gt;
             docker build 
             -t $CI_PROJECT/common:6.0.1 common
  </code></pre>
  
  <p>Below a dockerfile:</p>
  
  <pre><code>FROM ubuntu:bionic
  RUN apt-get update &amp;&amp; \
       DEBIAN_FRONTEND=noninteractive \
       apt-get install -y packages &amp;&amp; \
       apt-get clean &amp;&amp; \
       rm -rf /var/lib/apt/lists/*
  COPY file.conf /etc/common/
  </code></pre>