Docker GitLab-Runner安装
- GitLab-Runner
- 安装
- 问题合集
- GitLab 域名的配置修改
- Runner容器内注册失败,提示 'dial tcp: lookup home.zsl0.com on 192.168.254.2:53: no such host'
GitLab-Runner
安装
- 拉去gitlab/gitlab-runner镜像
docker pull gitlab/gitlab-runner:latest
- 运行容器:
docker run -d --name runner-java \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /opt/docker/gitlab-runner/runner-java/config:/etc/gitlab-runner \
gitlab/gitlab-runner:latest
- 进去容器
docker exec -it gitlab-runner /bin/bash
- 开始注册流程
获取url和token:
点击设置页面
概览 --> Runner --> 注册一个实例Runner
获取url和token
注册命令:
gitlab-runner register
root@c3faf0ff4921:/# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=50 revision=d89a789a version=16.4.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://home.zsl0.com:9080/
Enter the registration token:
xxxxx
Enter a description for the runner:
[c3faf0ff4921]:
Enter tags for the runner (comma-separated):
runner-java
Enter optional maintenance note for the runner:
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
Registering runner... succeeded runner=SdP2xtsF
Enter an executor: shell, ssh, virtualbox, docker-autoscaler, docker+machine, custom, docker, parallels, instance, docker-windows, kubernetes:
docker
Enter the default Docker image (for example, ruby:2.7):
docker
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
(其他注册方式,未使用这种)使用docker命令注册:
docker exec -it gitlab-runner gitlab-runner register --non-interactive --executor "docker" --docker-image alpine:latest --url "https://xx.xx.com" --registration-token "RQxx7UtMssiWyzWqtUMr" --description "172.30.7.17-docker-runner" --tag-list "docker-runner,share-runner,172.30.7.17-runner" --run-untagged="true" --locked="false" --access-level="not_protected"
- 编辑runner 勾选’运行未标记的作业’保存:
注:图片中名字runner-file-service
为注册时填写tags标签,可自行设置
勾选’运行未标记的作业’ --> 保存
- 修改confi.toml配置文件
敏感信息使用xxx替换,剩下的根据个人需求进行选择修改
concurrent = 10
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
# 用于配置远程镜像仓库拉取的认证
environment = ['DOCKER_AUTH_CONFIG={"auths": {"registry.cn-hangzhou.aliyuncs.com/zsl0/maven-build": {"auth": "xxxxxx"}}}']
name = "10e4d34ff34f"
url = "http://192.168.1.81:9080/"
id = 2
token = "xxxx"
token_obtained_at = 2023-10-20T03:24:03Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "maven:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
# 用于docker in docker
volumes = ["/var/run/docker.sock:/var/run/docker.sock","/cache"]
shm_size = 0
问题合集
GitLab 域名的配置修改
GitLab 域名的配置修改
Runner容器内注册失败,提示 ‘dial tcp: lookup home.zsl0.com on 192.168.254.2:53: no such host’
报错信息:
root@c3faf0ff4921:/# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=25 revision=d89a789a version=16.4.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://home.zsl0.com:9080/
Enter the registration token:
xxxxx
Enter a description for the runner:
[c3faf0ff4921]:
Enter tags for the runner (comma-separated):
runner-file-service
Enter optional maintenance note for the runner:
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
ERROR: Registering runner... failed runner=SdP2xtsF status=couldn't execute POST against http://home.zsl0.com:9080/api/v4/runners: Post "http://home.zsl0.com:9080/api/v4/runners": dial tcp: lookup home.zsl0.com on 192.168.254.2:53: no such host
PANIC: Failed to register the runner.
解决办法(临时解决):
因为猜测是没办法解析域名导致,正好运行Runner的宿主机也是运行GitLab的机器,直接去找宿主机就行了,所以执行
echo ‘172.17.0.1 home.zsl0.com’ >> /etc/hosts
重新注册命令:
gitlab-runner register
root@c3faf0ff4921:/# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=50 revision=d89a789a version=16.4.1
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
http://home.zsl0.com:9080/
Enter the registration token:
xxxxx
Enter a description for the runner:
[c3faf0ff4921]:
Enter tags for the runner (comma-separated):
runner-file-service
Enter optional maintenance note for the runner:
WARNING: Support for registration tokens and runner parameters in the 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with support for authentication tokens. For more information, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow
Registering runner... succeeded runner=SdP2xtsF
Enter an executor: shell, ssh, virtualbox, docker-autoscaler, docker+machine, custom, docker, parallels, instance, docker-windows, kubernetes:
docker
Enter the default Docker image (for example, ruby:2.7):
docker
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"