title: Cannot access docker daemon in gitlab runner using Kubernetes executor
body: <p>I setup my Gitlab instance using Kubernetes to deploy and also to do my CI using the Kubernetes cluster. <strong>Kubernetes is managed by Gitlab</strong>, so I did never touch the kubernetes by myself. <strong>Gitlab installed</strong> the four available packages: Helm Tiller Ingress, Cert-Manager, Prometheus and GitLab Runner.</p>
  
  <p>I installed the Kubernetes cluster on a barebone server using the tutorial from: <a href="https://vitux.com/install-and-deploy-kubernetes-on-ubuntu/" rel="nofollow noreferrer">https://vitux.com/install-and-deploy-kubernetes-on-ubuntu/</a>. The operating system of the server is Ubuntu 18.04 minimal. I found out, that Gitlab cannot install Helm Tiller on version 1.16 of Kubernetes so I installed the version 1.15.5-00 of Kubernetes on the server.</p>
  
  <h2>Problem:</h2>
  
  <p>I have a project, where I want to build a docker image. I try to use the dind service to build the docker image with the gitlab runner which is deployed on the kubernetes platform. </p>
  
  <p>The build process fails with the following output:</p>
  
  <pre><code>Running with gitlab-runner 12.1.0 (de7731dd)
    on runner-gitlab-runner-699dc9bcc8-sgmcw -YPHFGCL
  Using Kubernetes namespace: gitlab-managed-apps
  Using Kubernetes executor with image docker:stable ...
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-0qj6sn to be running, status is Pending
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-0qj6sn to be running, status is Pending
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-0qj6sn to be running, status is Pending
  Running on runner--yphfgcl-project-97-concurrent-0qj6sn via runner-gitlab-runner-699dc9bcc8-sgmcw...
  Fetching changes with git depth set to 50...
  Initialized empty Git repository in /builds/sadion/ci-test/.git/
  Created fresh repository.
  From https://git.sadion.net/sadion/ci-test
   * [new branch]      master     -&gt; origin/master
  Checking out d179001c as master...
  
  Skipping Git submodules setup
  $ docker --version
  Docker version 19.03.4, build 9013bf583a
  $ docker build -t $TEST_NAME .
  Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
  ERROR: Job failed: command terminated with exit code 1
  </code></pre>
  
  <h2>Source files:</h2>
  
  <p>The Dockerfile I am using is pretty simple and is also valid, since I was able to build the image on my local machine:</p>
  
  <pre><code>FROM httpd:2.4
  COPY ./index.html /usr/local/apache2/htdocs/
  </code></pre>
  
  <p>The <code>.gitlab-ci.yml</code> file I am using is:</p>
  
  <pre><code>image: docker:stable
  
  variables:
    TEST_NAME: local/test
  
  services:
    - docker:dind
  
  stages:
    - build
  
  before_script:
    - docker info
  
  build_docker_image:
    stage: build
    before_script:
      - docker --version
    script:
      - docker build -t $TEST_NAME .
    tags:
      - build
      - kubernetes
  
  </code></pre>
  
  <h1>Trying to export DOCKER_HOST</h1>
  
  <p>I also tried to export the <code>DOCKER_HOST</code> variable. But with that configured I get the same error:</p>
  
  <pre><code>image: docker:stable
  
  variables:
    TEST_NAME: local/test
    DOCKER_HOST: tcp://localhost:2375
  
  services:
    - docker:dind
  
  stages:
    - build
  
  before_script:
    - docker info
  
  build_docker_image:
    stage: build
    before_script:
      - docker --version
    script:
      - docker build -t $TEST_NAME .
    tags:
      - build
      - kubernetes
  </code></pre>
  
  <p>The output of the runner is:</p>
  
  <pre><code>Running with gitlab-runner 12.1.0 (de7731dd)
    on runner-gitlab-runner-699dc9bcc8-sgmcw -YPHFGCL
  Using Kubernetes namespace: gitlab-managed-apps
  Using Kubernetes executor with image docker:stable ...
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-042nmk to be running, status is Pending
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-042nmk to be running, status is Pending
  Waiting for pod gitlab-managed-apps/runner--yphfgcl-project-97-concurrent-042nmk to be running, status is Pending
  Running on runner--yphfgcl-project-97-concurrent-042nmk via runner-gitlab-runner-699dc9bcc8-sgmcw...
  Fetching changes with git depth set to 50...
  Initialized empty Git repository in /builds/sadion/ci-test/.git/
  Created fresh repository.
  From https://git.sadion.net/sadion/ci-test
   * [new branch]      master     -&gt; origin/master
  Checking out 57b6be1d as master...
  
  Skipping Git submodules setup
  $ docker --version
  Docker version 19.03.4, build 9013bf583a
  $ docker build -t $TEST_NAME .
  Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?
  ERROR: Job failed: command terminated with exit code 1
  </code></pre>