# GitLab runner using rootless docker

**URL:** <https://forum.gitlab.com/t/gitlab-runner-using-rootless-docker/107681>\
**Category:** GitLab CI/CD\
**Tags:** runner, docker\
**Created:** [July 16, 2024, 6:02am UTC](https://forum.gitlab.com/t/gitlab-runner-using-rootless-docker/107681 "2024-07-16T06:02:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephematician](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@stephematician](https://forum.gitlab.com/u/stephematician)\
**Post date:** [July 16, 2024, 6:02am UTC](https://forum.gitlab.com/t/gitlab-runner-using-rootless-docker/107681/1 "2024-07-16T06:02:18Z")

</div>

### Problem to solve

I’d like to be able to run the CI/CD tasks on my local machine (UbuntuMATE 22.04), using gitlab-runner, which

- is provided within a container, and;
- performs the jobs within another container;

using docker in rootless mode.

Following the instructions on [gitlab.com](http://gitlab.com) (see below) - the job fails with the following initial output:

```auto
Running with gitlab-runner 17.1.0 (fe451d5a)
  on test-add-ci <id>, system ID: <id>
Preparing the "docker" executor
ERROR: Failed to remove network for build
ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:958:0s)

```

After some guesswork, by modifying `config.toml` (see below) I succeeded in running the CI job within another container (using a ‘node’ image). However, I do not know if there is a simpler approach to setting up the runner.

### Steps to reproduce

I installed docker via APT:

```sh
sudo apt install docker-ce
# current version
docker --version
# ~$ Docker version 27.0.3, build 7d4bcd8

```

I then followed the instructions for setting up rootless mode for the docker daemon: [https://docs.docker.com/engine/security/rootless/](https://docs.docker.com/engine/security/rootless/).

- I installed gitlab-runner in a container as per: [https://docs.gitlab.com/runner/install/docker.html#option-2-use-docker-volumes-to-start-the-runner-container](https://docs.gitlab.com/runner/install/docker.html#option-2-use-docker-volumes-to-start-the-runner-container).
- I registered the runner with name `test-add-ci` as per: [https://docs.gitlab.com/runner/register/index.html?tab=Docker#register-with-a-runner-authentication-token](https://docs.gitlab.com/runner/register/index.html?tab=Docker#register-with-a-runner-authentication-token)
  - used executor to “docker” as in: [https://docs.gitlab.com/ee/ci/docker/using\_docker\_images.html](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html).

I believe the first problem is that item 2 in [Run GitLab Runner in a container](https://docs.gitlab.com/runner/install/docker.html#option-2-use-docker-volumes-to-start-the-runner-container) doesn’t have the right location for the socket when rootless mode is used:

```auto
docker run -d --name gitlab-runner --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v gitlab-runner-config:/etc/gitlab-runner \
    gitlab/gitlab-runner:latest

```

Typically the socket is at `/run/user/<number>/docker.sock` - this can be found via the shell command `docker ps`. Changing the `-v` option to point to the correct location did not affect the output.

However, once I set the `host` within `~/.local/share/docker/volumes/gitlab-runner-config/config.toml` via:

```toml
  [runners.docker]
    host = "unix:///run/user/<number>/docker.sock"

```

then the CI/CD pipeline seemed to function correctly. The problem is, I can’t tell if I’ve missed an instruction or if there is a simpler method for setting up the runner.

### Configuration

FWIW - I am using `node` images to run the CI jobs, e.g. my `.gitlab-ci.yml` is like:

```yml
stages:
  - greeting

image: node:20

job:
  stage: greeting
  script:
    - echo "Hello world"

```

### Versions

- Self-managed
- [GitLab.com](http://GitLab.com) SaaS
- Self-hosted Runners

Versions

- GitLab: via [https://gitlab.com](https://gitlab.com) “GitLab Enterprise Edition 17.2.0”
- GitLab Runner: 17.1.0
