<p>I use GitLab Runner on my Kubernetes cluster to run CI jobs. I want to make build jobs run faster.</p>

<p>To make them faster, I reuse Docker image from the previous build (tagged as <code>latest</code>). Build time has decreased, but now the bottleneck is the <code>pull</code> command which takes about 60-70% of the time.</p>

<p>Here's the snippet of the <code>.gitlab-ci.yml</code>:</p>

<pre><code>build:sheets:
  stage: build
  image: docker:stable
  services:
    - docker:dind
  before_script:
    - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin
  script:
    - docker pull $SHEETS_LATEST || true
    - docker build --cache-from $SHEETS_LATEST --tag $SHEETS_TAG --tag $SHEETS_LATEST .
    - docker push $SHEETS_TAG
    - docker push $SHEETS_LATEST
</code></pre>

<p>I use Gitlab Registry and thus <code>pull</code> command requires a lot of communication between my cluster and the registry.</p>

<p>So I have a couple of questions here:</p>

<ol>
<li><p><strong>Is it worth effort to deploy my own docker registry on the cluster to save a couple of minutes per build?</strong></p></li>
<li><p><strong>Is there a way to save an image somewhere on cluster to not pull from registry every time?</strong></p></li>
</ol>

stasdeep
<p>There are several methods to build Docker images in Pipeline quicker. </p>

<ol>
<li>DOOD (Docker out of Docker)</li>
</ol>

<p>Here you've to mount host's /var/lib/docker.sock inside your build container. It is vulnerable. But still too fast. </p>

<ol start="2">
<li>DIND (Docker in Docker)</li>
</ol>

<p>Here you can use dind image which has both docker cli and daemon. It doesn't communicate to host's docker daemon. The entire build process will happen within the pod. Not 100% secure but faster.</p>

<ol start="3">
<li>Kaniko, Makisu, Buildah </li>
</ol>

<p>These are Daemoneless next-generation image build tools and which does not depend on Docker daemon. More secure than DOOD and DIND also faster and supports caching. </p>
