How to install gitlab-runner using docker-compose
First, choose a directory where the service will reside in. I recommend /opt/gitlab-runner
. Then create docker-compose.yml
in said directory with this content:
gitlab-runner:
image: 'gitlab/gitlab-runner:latest'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./config:/etc/gitlab-runner
restart: unless-stopped
then run this command to configure the runner:
docker-compose exec gitlab-runner gitlab-runner register
It will ask you for details about the GitLab instance you want to attach to. You will find this information at https://<your-gitlab-domain>/admin/runners
. This example is for my GitLab instance:
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.techoverflow.net/
Enter the registration token:
Loo2lahf9Shoogheiyae
Enter a description for the runner:
[148a53203df8]: My-Runner
Enter tags for the runner (comma-separated):
Registering runner... succeeded runner=oc-oKWMH
Enter an executor: custom, docker-ssh, shell, virtualbox, docker-ssh+machine, docker, parallels, ssh, docker+machine, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Now, restart the runner that is running with the old config (i.e. with no gitlab instance being attached):
After that’s finished, you can run the script from our previous post Create a systemd service for your docker-compose project in 10 seconds in the directory where docker-compose.yml
is located.
This will automatically generate a systemd
service and start the runner (also on boot). For more details, see the corresponding blogpost. If your directory is named gitlab-runner
, the service file will be stored in /etc/systemd/systemd/gitlab-runner.service
, hence these are commands you can use to control the service:
Note that the script that creates the systemd service will automatically start the runner, so you don’t need to start
it manually. !
Start by
Restart by
Stop by
View status:
View & follow logs:
View logs in less
:
Also see Mini systemd cheat-sheet
Also see How to register gitlab runner for multiple GitLab instances.
Note that you can also use
to view the logs (run this from the directory where docker-compose.yml
) is located.
In case you see an error message like
in your jobs, see How to fix Gitlab CI error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on … no such host