Advanced
Searching inInstall guides
How to search
  • Paste an error message in quotes, e.g. "permission denied", to find the fix table that explains it.
  • Choose an area and a part of the guide (install, first settings, daily use, security, fixes) to go straight to the right step.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Guide 20GitLab Runner · Git and CI/CD

Install and set up GitLab Runner

GitLab Runner is the agent that runs the jobs of GitLab CI/CD pipelines: tests, builds, scans and deploys. GitLab.com has shared runners, but companies run their own runners for speed, private networks, special hardware and control over security. This guide installs GitLab Runner on RHEL and Ubuntu, registers it with the new runner token, sets up the Docker executor safely, and runs a first pipeline.

  • 10 Lessons
  • 8 Commands

$ run as a normal user# run as root (or with sudo)

20.1

Know it before you install

The runner asks GitLab for jobs (it connects out to GitLab, so no inbound port is needed). For each job it uses an executor: docker (each job in a fresh container — the most used), shell (on the host), kubernetes (each job in a Pod) and others.

ItemValue
Packagegitlab-runner (from packages.gitlab.com)
Servicegitlab-runner.service, runs as user gitlab-runner
Config/etc/gitlab-runner/config.toml
Logsjournalctl -u gitlab-runner
Networkoutbound HTTPS (443) to your GitLab; no inbound port
Docker executor needsDocker Engine on the same machine

20.2

Install on RHEL, Rocky, Alma and Fedora

The GitLab script adds the repository; then install the package:

curl -fsSL https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh -o /tmp/runner-repo.sh
less /tmp/runner-repo.sh
bash /tmp/runner-repo.sh
dnf -y install gitlab-runner
gitlab-runner --version

20.3

Install on Ubuntu and Debian

curl -fsSL https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh -o /tmp/runner-repo.sh
bash /tmp/runner-repo.sh
apt-get install -y gitlab-runner
systemctl status gitlab-runner --no-pager

For the Docker executor, install Docker Engine too (see the Docker guide). The runner talks to Docker through the socket.

20.4

Register the runner

In GitLab, open your project (or group): Settings → CI/CD → Runners → New project runner. Add tags (for example docker, linux), choose if it may run untagged jobs, and click Create runner. GitLab shows a runner authentication token that starts with glrt-. Use it on the server:

gitlab-runner register --non-interactive --url https://gitlab.com --token glrt-XXXXXXXXXXXXXXXXXXXX --executor docker --docker-image alpine:3.22 --description "build-01"
Runner registered successfully.
gitlab-runner verify
gitlab-runner list

Note

The token is shown only once and works like a password. The old way with a registration token and --registration-token is deprecated; use the runner token from the UI or API.

20.5

First configuration: config.toml

After registering, tune the file. The most important settings:

/etc/gitlab-runner/config.toml
concurrent = 4
check_interval = 3
 
[[runners]]
  name = "build-01"
  url = "https://gitlab.com"
  token = "glrt-XXXXXXXXXXXXXXXXXXXX"
  executor = "docker"
  [runners.docker]
    image = "alpine:3.22"
    privileged = false
    pull_policy = ["if-not-present"]
    volumes = ["/cache"]
    shm_size = 0
    memory = "4g"
    cpus = "2"
    allowed_images = ["registry.example.com/*", "docker.io/library/*", "alpine:*"]
SettingWhy
concurrentHow many jobs run at the same time on this machine (about 1 per 2 CPU).
privileged = falseJobs can not get root on the host. Turn on only for Docker-in-Docker runners you trust.
pull_policy if-not-presentFaster jobs; use always when images can change under the same tag.
memory, cpusOne job can not take the whole machine.
allowed_imagesJobs may use only images from places you trust.

The runner reads the file again by itself after a change; check with journalctl -u gitlab-runner -f.

Watch out

The shell executor runs jobs directly on the host as the gitlab-runner user. If that user is in the docker group, every job is root on the host. Use the Docker or Kubernetes executor for untrusted code and merge requests.

20.6

Your first pipeline

Put .gitlab-ci.yml in the root of the repository:

.gitlab-ci.yml
stages: [test, build, scan]
 
default:
  tags: [docker]
 
test:
  stage: test
  image: python:3.12-slim
  script:
    - pip install -r requirements.txt
    - python -m pytest -q
 
build:
  stage: build
  image: quay.io/buildah/stable
  script:
    - buildah bud -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" .
    - buildah push --creds "$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
 
scan:
  stage: scan
  image:
    name: aquasec/trivy:latest
    entrypoint: [""]
  script:
    - trivy fs --exit-code 1 --severity HIGH,CRITICAL .

Push it, then watch the job in Build → Pipelines. The job log shows Running with gitlab-runner … on build-01.

Daily commands on the runner machine:

gitlab-runner status
gitlab-runner verify
journalctl -u gitlab-runner -f
gitlab-runner unregister --name build-01
docker system df
docker system prune -af --filter "until=72h"

Real uses at work:

  • Fast builds close to your network: private registries, databases for tests, on-prem deploy targets.
  • Protected runners only for protected branches — they hold the deploy credentials for production.
  • Special runners: GPU, ARM, Windows, macOS, big memory.

20.7

Make it safe

Security checklist:

  • Docker executor with privileged = false; build images with Buildah or Kaniko instead of Docker-in-Docker.
  • Separate runners: one for merge requests (no secrets), protected ones for deploys.
  • The runner token is a password: keep config.toml at 600, rotate the token if it leaks.
  • Use masked and protected CI/CD variables for secrets; prefer OIDC (id_tokens) to get cloud access without stored keys.
  • Limit images (allowed_images), CPU and memory.
  • Clean old images and volumes (cron with docker system prune); update the runner every month.

20.8

Update and remove

dnf -y upgrade gitlab-runner
apt-get install --only-upgrade -y gitlab-runner
gitlab-runner unregister --all-runners
dnf -y remove gitlab-runner
apt-get purge -y gitlab-runner

Delete the runner also in GitLab (Settings → CI/CD → Runners), so its token stops working.

20.9

Fix common problems

ProblemCauseFix
Job pending: "This job is stuck because you don't have any active runners that can run this job"No online runner with the job's tags.Check the tags in the job and on the runner; allow untagged jobs; gitlab-runner verify.
Cannot connect to the Docker daemon at unix:///var/run/docker.sockDocker is not running, or the runner has no access.systemctl start docker; for the shell executor add gitlab-runner to the docker group (root risk).
x509: certificate signed by unknown authoritySelf-hosted GitLab with a company CA.Put the CA in /etc/gitlab-runner/certs/gitlab.example.com.crt or use --tls-ca-file.
Runner shows "never contacted" or offlineToken wrong, no outbound HTTPS, or service stopped.gitlab-runner verify; curl -I https://gitlab.com; systemctl status gitlab-runner.
no space left on device in jobsOld images, volumes and cache.docker system prune -af; a cleanup cron; bigger disk.
ERROR: Job failed: execution took longer than 1hJob timeout.Make the job faster, or raise the timeout in the project/runner settings.
Jobs on Docker-in-Docker failprivileged is off (as it should be).Use Buildah or Kaniko to build images.

20.10

Next steps

1Does the runner need an open inbound port?

No. It connects out to GitLab over HTTPS and asks for jobs.

2Why is privileged = true dangerous on a shared runner?

A job can then get root on the host and read other jobs' data and secrets.

All commands in this chapter