Creating a Custom Runner on Gitlab

Stephen Olabode
3 min readNov 7, 2019

(DOCKER RUNNER AS A CASE STUDY)

Hey guys, on this post, I’ll discuss with you how to create a custom runner that works for running docker jobs on your gitlab ci. It’s quite an easy process to achieve provided each steps are followed accordingly. First things first, you’ll need to install the gitlab-runner and there’re different ways to do that, you can read that up on gitlab docs using this link https://docs.gitlab.com/runner/install/ .

For the purpose of this post, I’ll be using the the installation process of “running gitlab in a container”. NOTE that this explanation is being made with the assumption that you have docker installed already. The first thing to do then is the need to mount a config volume in the ‘gitlab-runner’ container to be used for configs in your terminal. That is done by running this command in your terminal; (insert a container name you desire after the name tag).

docker run -d --name [container-name] --restart always --privileged   -v $(pwd):/etc/gitlab-runner   -v /var/run/docker.sock:/var/run/docker.sock    gitlab/gitlab-runner:latest

The next thing to do after this is done is to get the runner registered in the container already created. I personally like doing this with the ‘one line registration command’ because i get to see all the my configuration at one glance. This is done by running this command next in your terminal; (insert a runner name you so desire to).

docker run --rm -t -i  -v $(pwd):/etc/gitlab-runner gitlab/gitlab-runner register \
--non-interactive \
--name [runner-name] \
--url https://gitlab.com/ \
--registration-token "[code]" \
--tag-list "docker" \
--run-untagged \
--executor docker \
--docker-image "docker:latest" \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock \
--docker-privileged

The registration token is found on your gitlab project page, access it by clicking on Settings > CI/CD > Runners, expand the Runners tab and check out the registration token under the specific runner (that’s probably the 3rd highlighted step). Once you have your token inserted into the command above, then you click enter. If that’s successful, you should have something similar to this

Then go back to your gitlab project page, reload the runners page (where you got your registration token from) and you should have an active runner on the page, something that looks like the image below. As you will notice, I have the ‘disable shared runners’ tab active; that is to ensure the project job is picked up by the custom runner when triggered.

If you have this same result, congratulations because you now know how to create a custom runner that works best for whatever project you need to run. I’m readily available to answer any question related to this post. Cheers.

--

--

Stephen Olabode

DevOps Engineer | AWS Enthusiast | Cloud Computing | Solutions Architect