How to Set Up a GitLab Runner with Docker Executor on a VPS

Running your own GitLab Runner Docker Executor on a VPS puts your CI pipeline on hardware you control, with no per-minute billing and no queue behind other tenants. Each job spins up a fresh container, runs, and disappears, so a broken build cannot poison the next one. This guide walks through the whole setup on Ubuntu 24.04: Docker, the runner binary, registration, a tuned config, and a first real pipeline.

What the Docker Executor Actually Does

GitLab Runner is the agent that picks up jobs from your GitLab instance and runs them. The executor decides where each job runs. The shell executor runs jobs directly on the host, which means build tools, stray files, and leftover processes pile up on your server. The Docker executor instead starts a clean container from an image you choose in .gitlab-ci.yml, runs the job inside it, then removes the container. Two jobs can use two different images on the same host without stepping on each other.

That isolation is the main reason to pick Docker over shell for a self-hosted runner. It also keeps your host tidy: compilers, test databases, and Node versions live in images, not in the VPS. The trade-off is a small startup cost per job, usually a few seconds to pull or start the image. For most small teams and solo developers, that trade is worth it. If you want the broader picture first, our guide to hosting your own GitLab Runner on a VPS for private CI covers the shell executor and the sizing decisions around it.

What You Need Before You Start

You need a VPS with at least 2 GB of RAM and 2 vCPUs. One gigabyte can run a runner, but a single heavy job plus the Docker daemon will push it into swap, and builds will crawl. Give the disk at least 25 GB free: images, caches, and job artifacts add up fast, and Docker stops pulling when the disk fills. Ubuntu 24.04 is used here; the steps translate to Debian with minor package-name changes.

You also need a GitLab instance, self-hosted or GitLab.com, and access to a project or group where you can create a runner. Grab a registration token from Settings > CI/CD > Runners in that project, or from the group settings if you want the runner shared across projects. Keep the token handy; you will paste it once during registration and never see it again.

Install Docker on the VPS

Install Docker from the official Docker repository, not the older package in the Ubuntu archive. The archive version lags behind, and the runner’s Docker executor works best with a current daemon. Add Docker’s key and repository, then install the engine:

sudo apt update
sudo apt install -y ca-certificates curl gnupg
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
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
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Check the daemon with sudo docker run hello-world. If the test image prints its greeting, Docker works. Add your user to the docker group so you can run Docker commands without sudo, then log out and back in. For a fuller walkthrough of the Compose side of the install, see our guide to installing Docker Compose on Ubuntu 24.04.

Install GitLab Runner

GitLab ships an official repository for the runner. Add it and install the package:

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

The package creates a gitlab-runner system user and a systemd service. Check that it is running with sudo systemctl status gitlab-runner. At this point the runner is installed but unregistered, so it will not pick up any jobs. Registration is the step that ties this machine to your GitLab instance.

Register a GitLab Runner Docker Executor

To register GitLab Runner, run the interactive command and answer the prompts:

sudo gitlab-runner register --url https://gitlab.com --token glrt-xxxxxxxxxxxx

Replace the URL with your own GitLab instance if you self-host, and paste the token you copied earlier. When asked for an executor, type docker. For the default image, enter alpine:latest or ubuntu:24.04. The default image only matters for jobs that do not specify their own image, so pick something small and sane. Give the runner a short description such as vps-docker-01, and add tags like docker,vps if you want jobs to select this runner explicitly.

Registration writes /etc/gitlab-runner/config.toml. That file is the heart of your runner, and the next section tunes it. A self-hosted GitLab Runner that only ever runs untagged jobs is fine for a single project, but tags keep you in control as more projects share the machine.

Tune config.toml for Real Jobs

Open the GitLab Runner config.toml file and check three settings before you run anything serious. First, concurrent sets how many jobs run at once. On a 2 vCPU box, 2 is a sensible start; more than that and jobs start fighting for CPU. Second, check_interval controls how often the runner asks GitLab for work. The default of 3 seconds is fine. Third, the [runners.docker] section holds the executor options.

Set pull_policy to if-not-present so the runner reuses images it already has instead of pulling on every job. Add a volume for the Docker cache if your builds use one, and keep privileged = false unless a specific job genuinely needs Docker-in-Docker. Privileged containers can touch the host, so leave it off by default. A typical tuned block looks like this:

concurrent = 2
check_interval = 3

[[runners]]
  name = "vps-docker-01"
  url = "https://gitlab.com"
  executor = "docker"
  [runners.docker]
    image = "alpine:latest"
    privileged = false
    pull_policy = "if-not-present"
    volumes = ["/cache"]

After editing, restart the runner with sudo gitlab-runner restart and confirm the new config loads without errors in sudo gitlab-runner verify. If your builds need images from your own registry, read our guide to running a private Docker registry on your VPS before wiring credentials into the runner.

Test It with a Real Pipeline

The fastest test is a tiny pipeline that proves the GitLab CI Docker executor starts a container, runs a command, and reports back. Add this to .gitlab-ci.yml in your project:

stages:
  - test

smoke-test:
  stage: test
  tags:
    - docker
  image: alpine:latest
  script:
    - echo "Runner is alive on $(hostname)"
    - cat /etc/os-release

Push the file and watch the job in GitLab’s CI/CD > Pipelines view. A healthy run shows the job picked up by your runner within seconds, the container starting, and the output lines printed. If the job stays pending, check the tags: an untagged job will not run on a tagged runner, and a tagged job will not run on an untagged one. That mismatch is the most common first-run failure.

Keep the Runner Secure

A runner executes code from your repositories, so treat it like a build server, not a spare box. Run it as the dedicated gitlab-runner user, never as root. Keep the Docker socket out of job containers: mounting /var/run/docker.sock into a job gives that job root-equivalent access to the host, and a malicious or compromised job could escape the container. If you need Docker-in-Docker, use the official docker:dind service image with TLS instead of the socket mount.

Rotate the runner token if anyone who had access to it leaves the project, and re-register rather than sharing tokens between machines. Keep the host patched with unattended upgrades for security updates, and lock SSH down to key-only login. Job logs can contain secrets if a script echoes them, so use GitLab’s masked CI/CD variables and never print credentials in a build step.

Fix the Failures You Will Hit

Three problems show up on nearly every new runner. First, “no runner available” usually means a tag mismatch or the runner being paused in GitLab’s settings. Unpause it and check the tags. Second, image pull failures point at the registry or the network: check that the VPS can reach the registry and that private images have credentials configured in the project. Third, jobs that die with “no space left on device” mean Docker’s layers filled the disk. Schedule a weekly docker system prune so it never gets that far. Pair that habit with automatic restarts: our walkthrough of auto-restarting crashed Docker containers on your VPS keeps both the daemon and the runner service coming back after a reboot or a crash.

Once the smoke test is green and the first real pipeline runs end to end, the runner is ready for daily work. Check in on it weekly: disk space, runner version, and any jobs that sat pending longer than usual.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.