title: Gitlab Runner with Docker and shell error — Permission denied
body: <p>Installed a brand new Gitlab CE 13.9.1 on a Ubuntu Server 20.04.2.0.
  This is the pipeline</p>
  <pre><code>image: node:latest
  
  before_script:
    - apt-get update -qq
  
  stages:
    - install
  
  install:
    stage: install
    script:
      - npm install --verbose
  </code></pre>
  <p>To run it I configure my Gitlab Runner using the same procedure as in my previous Gitlab CE 12:</p>
  <p>I pull last Gitlab runner image:</p>
  <pre><code>docker pull gitlab/gitlab-runner:latest
  </code></pre>
  <hr />
  <p><strong>First try:</strong></p>
  <p>Start GitLab Runner container mounting on local volume</p>
  <pre><code>docker run -d \
  --name gitlab-runner \
  --restart always \
  -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest
  </code></pre>
  <p>And register runner</p>
  <pre><code>docker run --rm -t -i \
  -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register
  </code></pre>
  <p>When registering runner, for executor I pick <code>shell</code></p>
  <p>Finally, when I push to Gitlab, on the pipeline, I see this error:</p>
  <pre><code>$ apt-get update -qq
  E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
  ERROR: Job failed: exit status 1
  </code></pre>
  <hr />
  <p><strong>Second try:</strong></p>
  <p>Start GitLab Runner container mounting on Docker volume</p>
  <ol>
  <li>Create volume</li>
  </ol>
  <pre><code>docker volume create gitlab-runner-config
  </code></pre>
  <ol start="2">
  <li>Start GitLab Runner container</li>
  </ol>
  <pre><code>docker run -d \
  --name gitlab-runner \
  --restart always \
  -v gitlab-runner-config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest
  </code></pre>
  <ol start="3">
  <li>Register runner (picking shell again as executor)</li>
  </ol>
  <pre><code>docker run \
  --rm -t -i \
  -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register
  </code></pre>
  <p>Same results.</p>
  <pre><code>$ apt-get update -qq
  E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
  ERROR: Job failed: exit status 1
  </code></pre>
  <hr />
  <p><strong>Third try:</strong></p>
  <p>Granting permissions to gitlab-runner</p>
  <p>I ended up reading <a href="https://stackoverflow.com/questions/50678061/in-gitlab-ci-the-gitlab-runner-choose-wrong-executor">In gitlab CI the gitlab runner choose wrong executor</a> and <a href="https://docs.gitlab.com/runner/executors/shell.html#running-as-unprivileged-user" rel="nofollow noreferrer">https://docs.gitlab.com/runner/executors/shell.html#running-as-unprivileged-user</a>, which states these solutions:</p>
  <blockquote>
  <ol>
  <li>move to docker</li>
  <li>grant user gitlab-runner the permissions he needs to run specified commands. gitlab-runner may run apt-get without sudo, also he will need perms for npm install and npm run.</li>
  <li>grant sudo nopasswd to user gitlab-runner. Add gitlab-runner ALL=(ALL) NOPASSWD: ALL (or similar) to /etc/sudoers on the machine gitlab-runner is installed and change the lines apt-get update to sudo apt-get update, which will execute them as privileged user (root).</li>
  </ol>
  </blockquote>
  <ol>
  <li>I need to use <code>shell</code></li>
  <li>I already did that with <code>sudo usermod -aG docker gitlab-runner</code></li>
  <li>Tried as well with <code>sudo nano /etc/sudoers</code>, adding <code>gitlab-runner ALL=(ALL) NOPASSWD: ALL</code>, and using <code>sudo apt-get update -qq</code> in the pipeline, which results in <code>bash: line 106: sudo: command not found</code></li>
  </ol>
  <p>I'm pretty lost here now. Any idea will be welcome.</p>