Installing and Configuring GitLab Runner on Ubuntu Server with Docker Executor

Which Executor Should You Choose for GitLab Runner?

When setting up CI/CD with GitLab, the first question you need to answer is: where will your Runner execute jobs? GitLab supports several types of executors. However, in roughly 90% of real-world projects, you will primarily encounter the following three:

  • Shell Executor: The pipeline runs bash commands directly on the host server’s operating system. All dependencies—such as Node.js, Python, Java, or the Docker CLI—must be pre-installed on the host machine.
  • Docker Executor: Every job runs inside an isolated container spun up from a specified Docker image (such as node:20-alpine). Once finished, the Runner automatically tears down the container, leaving a clean slate for the next run.
  • Kubernetes Executor: The Runner calls the K8s cluster API to create temporary Pods for executing jobs and handles cleanup afterward.

Comparing Real-World Pros and Cons

Each approach involves a clear trade-off between operational overhead and isolation/security:

1. Shell Executor

  • Pros: Extremely fast setup with virtually no additional RAM or CPU overhead beyond the job process itself. Jobs start instantly since there is no need to pull images from a registry.
  • Cons: No isolation. A job executing npm install -g or switching the global Python version will immediately break other pipelines. Security risks are also high if a pipeline accidentally executes commands that overwrite system files using root privileges.

2. Docker Executor

  • Pros: Complete isolation. Does your frontend repository require Node 18 while the backend requires Python 3.11? Simply declare a single image: ... line in your .gitlab-ci.yml file. You never have to worry about host-level version conflicts.
  • Cons: Consumes an additional 200MB to 400MB of RAM for the Docker daemon. The initial run takes an extra 30 to 60 seconds to pull the base image into local cache.

3. Kubernetes Executor

  • Pros: Exceptional auto-scaling capabilities. It is the ideal choice for large enterprises with dozens of teams triggering hundreds of concurrent pipelines.
  • Cons: High technical barrier to entry. Setting up and maintaining a K8s cluster solely to run runners for a small team of 5–10 developers is an unnecessary waste of resources and operational effort.

Why Docker Executor Is the Best Choice for a Single Server

For small and medium product teams, the Docker Executor offers the optimal balance. You get granular control over the build environment of each project without the overhead of complex infrastructure.

In practice, on an Ubuntu 22.04 VPS with 4 vCPUs and 8GB of RAM, you can comfortably run 3 to 4 concurrent build jobs without worrying about port collisions or overwritten files between projects.

Steps to Install and Configure GitLab Runner

Step 1: Install Docker Engine on Ubuntu

Your server must have Docker Engine installed before setting up the Runner. Run the following commands to install official Docker CE:

sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg lsb-release

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the Docker service is active and running properly:

sudo systemctl status docker --no-pager

Step 2: Install GitLab Runner from the Official Repository

Register the GitLab repository to easily manage updates via apt:

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash
sudo apt-get install -y gitlab-runner

Verify that the runner process is running:

sudo gitlab-runner status

Step 3: Create an Authentication Token in GitLab

Starting with GitLab 16.0+, the registration workflow uses Authentication Tokens instead of legacy Registration Tokens:

  1. To share across an entire group: go to Group Settings > CI/CD > Runners.
  2. For a single repository: go to the project > Settings > CI/CD > expand the Runners section.
  3. Click New project runner. Add tags for identification (e.g., docker-runner), then click Create runner. GitLab will generate a token prefixed with glrt-.... Copy this value.

Step 4: Register the Runner with Docker Executor

Open a terminal on your server and launch the interactive registration command:

sudo gitlab-runner register

Enter the requested details when prompted:

  1. GitLab instance URL: Enter https://gitlab.com/ or your self-hosted GitLab server URL.
  2. Authentication token: Paste the glrt-... token obtained in Step 3.
  3. Name: Provide a descriptive name, such as vps-ubuntu-docker-01.
  4. Executor: Enter docker.
  5. Default Docker image: Specify a fallback image for pipelines that do not define one, such as alpine:latest.

Upon successful registration, the terminal will display: “Runner registered successfully.”

Step 5: Fine-Tune the config.toml File

Open the primary configuration file located at /etc/gitlab-runner/config.toml to adjust concurrency and configure socket mounting:

sudo nano /etc/gitlab-runner/config.toml

An optimized sample configuration looks like this:

concurrent = 4
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "vps-ubuntu-docker-01"
  url = "https://gitlab.com/"
  id = 123456
  token = "glrt-xxxxxxxxxxxx"
  token_obtained_at = 2026-01-01T00:00:00Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

Pay close attention to these two key parameters:

  • concurrent = 4: Limits execution to a maximum of 4 concurrent jobs. Sizing should match your server capacity—each job typically requires around 1 vCPU and 1GB to 2GB of RAM.
  • volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]: The Docker-outside-of-Docker (DooD) pattern. This allows containers within the pipeline to communicate directly with the host’s Docker daemon to build Docker images without enabling the risky privileged: true flag.

Restart the runner to apply your changes:

sudo gitlab-runner restart

Step 6: Test the Pipeline to Validate the Environment

Create a .gitlab-ci.yml file in the root directory of your repository to verify operation:

stages:
  - test
  - build

unit-test:
  stage: test
  image: node:20-alpine
  script:
    - node -v
    - echo "Node.js test ran successfully inside an isolated container!"

check-os:
  stage: build
  image: ubuntu:22.04
  script:
    - cat /etc/os-release
    - echo "Build job completed safely in an isolated environment!"

Push your commit to GitLab and navigate to Build > Pipelines. Both jobs will automatically be assigned to your Ubuntu runner, pull the required images, and complete within 10 to 20 seconds.

Share: