first step
# 拉取镜像
docker pull gitlab/gitlab-runner:latest
# 启动容器
docker run -d --name gitlab-runner --restart always -v /opt/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
second step
View /var/run/docker.sock permissions
It is found that only the root user and the docker group have rw permissions, enter the following command to modify
sudo chown root:root /var/run/docker.sock
The root user and root group have rw permissions
third step:
Add container permissions to ensure that the container can use the host's docker
docker exec -it gitlab-runner usermod -aG root gitlab-runner
the fourth step:
Integrate gitlab and gitlab-runner together
1. First create a project in gitlab
2. Register gitlab-runner to gitlab
docker exec -it gitlab-runner gitlab-runner register
Then enter the specific information according to the way it asks.
The path of gitlab, the search method is as follows: log in to GitLab, select Settings, select CI/CD, find Runner and click to expand
The above is the path you want to enter in " Runner settings specify the following URL ", and the following registration token, which is token
Enter the contents of the red line in the above picture in turn to register the runner.
At this point, the runner is integrated with the new project my-ssm-project in my gitlab
View on gitlab to see the runner information just added.
Common commands for gitlab-runner are as follows:
gitlab-runner register #默认交互模式下使用,非交互模式添加 --non-interactive
gitlab-runner list #此命令列出了保存在配置文件中的所有运行程序
gitlab-runner verify #此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。 --delete 删除
gitlab-runner unregister #该命令使用GitLab取消已注册的runner。
#使用令牌注销
gitlab-runner unregister --url http://gitlab.example.com/ --token t0k3n
#使用名称注销(同名删除第一个)
gitlab-runner unregister --name test-runner
#注销所有
gitlab-runner unregister --all-runners
For a detailed explanation of GitLab-Runner, see this article: