title: gitlab-runner - docker in docker (dind) and push to GitLab registry
body: <p>I wish to use <a href="https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#using-the-gitlab-container-registry" rel="nofollow noreferrer">GitLab Container Registry</a> to temporary store my newly built Docker image; in order to have Docker function (i.e. docker login, docker build, docker push), I applied <a href="https://docs.gitlab.com/ce/ci/docker/using_docker_build.html#use-docker-in-docker-executor" rel="nofollow noreferrer">docker-in-docker executor</a>; then from GitLab Piplelines error messages, I realize I need to place a Dockerfile at project root:-</p>
  
  <pre><code>$ docker build --pull -t $CONTAINER_TEST_IMAGE .
  unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /builds/xxxxx.com/laravel/Dockerfile: no such file or directory
  </code></pre>
  
  <p>My Dockerfile includes centos:7, php, nodejs, composer and sass installations. I observe after each commit, GitLab runner will go through the Dockerfile once and install all of them from beginning, which makes the whole build stage very slow and funny - how come I just want to amend 1 word in my project but I need to install so many things again for deployment?</p>
  
  <hr>
  
  <p>From my imagination, it will be nice if I can pre-build a Docker image from a Dockerfile that contains the installations mentioned above plus Docker (so that docker login, docker build and docker push can work) and stored in the GitLab-runner server, and after each commit, this image can be reused to build the new image to be pushed to  GitLab Container Registry.</p>
  
  <p>However, I faced 2 problems:-</p>
  
  <p>1) Even I include Docker installation in the pre-build a Docker image, I cannot systemctl docker start, due to some D-bus problem</p>
  
  <pre><code>Failed to get D-Bus connection: Operation not permitted
  </code></pre>
  
  <p>moreover some articles also mentioned a docker in container shall not run background services;</p>
  
  <p>2) when I use dind, it will require a Dockerfile at project root; with the pre-build a Docker image, actually I have nothing to do with this Dockerfile at project root; hence is dind a wrong option?</p>
  
  <p>Acutally, what is the proper way to push a Laravel project image to GitLab Container Registry? (where to place those npm install and composer install commands?)</p>
  
  <pre><code>image: docker:latest
  services:
  - docker:dind
  
  stages:
    - build
    - test
    - deploy
  
  variables:
    CONTAINER_TEST_IMAGE: xxxx
    CONTAINER_RELEASE_IMAGE: yyyy
  
  before_script:  
    - docker login -u xxx -p yyy registry.gitlab.com 
  
  build:
    stage: build
    script:
      - npm install here?
      - docker build --pull -t $CONTAINER_TEST_IMAGE .
      - docker push $CONTAINER_TEST_IMAGE
  </code></pre>