title: Docker login before pulling image for GitLab Runner
body: <p>I have set up a docker runner, where I want to run an image stored on a local repository.  My /etc/gitlab-runner/config.toml is</p>
  <pre><code>concurrent = 1
  check_interval = 0
  
  [session_server]
    session_timeout = 1800
  
  
  [[runners]]
    name = &quot;Docker runner&quot;
    url = &quot;https://gitlab.str.corp/&quot;
    token = &quot;*secret*&quot;
    executor = &quot;docker&quot;
    [runners.custom_build_dir]
    [runners.cache]
      [runners.cache.s3]
      [runners.cache.gcs]
      [runners.cache.azure]
    [runners.docker]
      tls_verify = false
      image = &quot;gitlab.example.com:4443/docker:19.03.1-dind&quot;
      privileged = true
      disable_entrypoint_overwrite = false
      oom_kill_disable = false
      disable_cache = false
      volumes = [&quot;/certs/client&quot;, &quot;/cache&quot;]
      shm_size = 0
  </code></pre>
  <p>When I submit the job, it starts on the runner, but fails to pull the image:</p>
  <pre><code>Running with gitlab-runner 13.4.0 (4e1f20da)
    on Docker runner abcde123
  
  Preparing the &quot;docker&quot; executor
  Using Docker executor with image gitlab.example.com:4443/docker:19.03.8-git ...
  Starting service gitlab.example.com/docker:19.03.1-dind ...
  Authenticating with credentials from /root/.docker/config.json
  Pulling docker image gitlab.example.com:4443/docker:19.03.1-dind ...
  ERROR: Job failed: Error response from daemon: pull access denied for gitlab.example.com:4443/docker, repository does not exist or may require 'docker login': denied: requested access to the resource is denied (docker.go:142:0s)
  </code></pre>
  <p>The <code>docker login</code> is the problem.  If I try to do <code>docker pull &lt;image&gt;</code> from the command line, I get the same error.  A docker login then lets me pull the image.</p>
  <p>I am pretty certain that I just need to do <code>echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY</code> before pulling the image, but I don't know how to cause that to be run.</p>
  <p>The docker image is stored in the gitlab integrated repository.  <a href="https://docs.gitlab.com/runner/configuration/advanced-configuration.html#support-for-gitlab-integrated-registry" rel="nofollow noreferrer">This page</a> makes it seem that the authentication should be automatically set up, but that is clearly not the case.</p>
  <p>What do I need to do to be able to be able to pull the privately stored image.</p>