How to run gitlab-runner with docker

How to run gitlab-runner with Docker

How to run gitlab-runner with Docker

The official document can be found here.

create a docker volume

docker volume create gitlab-runner-config

run the gitlab-runner container

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

register a project with gitlab-ruuner container ( it is in interactive mode)

docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register

check the configuration file of gitlab-runner

[root@docker ~]# cat /var/lib/docker/volumes/gitlab-runner-config/_data/config.toml 
concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "gitlab-tmp-project"
  url = "https://gitlab.com/"
  token = "GssVseaD_s_dyv342WS4"
  executor = "shell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

login to it

docker exec -it $(docker ps | grep 'gitlab\-runner' | cut -d' ' -f1) bash

go into home directory

from here you can see your pipeline output NOTE that you have set home directory ( ~ ) in your gitlab-ci.yml file

cd /home/gitlab-runner

running the whole process in one script

#!/bin/bash
# gitlab-runner with docker
# official doc
# https://docs.gitlab.com/runner/install/docker.html

# create a docker volume
docker volume create gitlab-runner-config


# run the gitlab-runner container 
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


# register a project with gitlab-ruuner container ( it is in interactive mode)
docker run --rm -it -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner register

# check the configuration file of gitlab-runner
cat /var/lib/docker/volumes/gitlab-runner-config/_data/config.toml 

# login to it
docker exec -it $(docker ps | grep 'gitlab\-runner' | cut -d' ' -f1) bash


# go into home directory , from here you can see your pipeline output
# NOTE that you have set home directory ( ~ ) in your gitlab-ci.yml file
cd /home/gitlab-runner

screenshot of the result

the top terminal is my local machine and below that is the gitlab-runner with docker

Last updated

Was this helpful?