在gitlab集成gitlab-runner执行job时候,发现获取本地私服registry发生错误,日志如下:
Running with gitlab-runner 15.8.0 (12335144)
on runner run in the docker container,depend some images need difine in the config or gitlab-ci file 3ea798cc, system ID: r_ObcQtykLpVY0
Preparing the "docker" executor
Using Docker executor with image centos:7-maven-lrn1.3 ...
Pulling docker image centos:7-maven-lrn1.3 ...
WARNING: Failed to pull image with policy "if-not-present": manifest for docker.io/centos:7-maven-lrn1.3 not found (manager.go:237:18s)
ERROR: Job failed: failed to pull image "centos:7-maven-lrn1.3" with specified policies [if-not-present]: manifest for docker.io/centos:7-maven-lrn1.3 not found (manager.go:237:18s)
一、gitlab-runner安装过程省略
二、gitlab-runner registry 过程省略
三、docker私有仓库安装省略
三、私服仓库配置相关
如果要在gitlab-runner运行过程中访问私有仓库,需要配置环境变量DOCKER_AUTH_CONFIG,具体方法以centos7操作为例:
1,凭证信息通过docker login生成
docker login 10.100.19.86:5000 --username admin --password admin
2,查看~/docker/config.json
{
"auths": {
"10.100.19.86:5000": {
"auth": "YWRtaW46YWRtaW4="
}
}
}
auth参数值通过base64生成
echo -n "admin:admin" | base64
# 示例
YWRtaW46YWRtaW4=
# 格式
{
"auths": {
"registry.example.com:5000": {
"auth": "(Base64 content from above)"
}
}
}
3,格式化凭证信息(json串)
{"auths": {"10.100.19.86:5000": {"auth": "YWRtaW46YWRtaW4="}}}
4,项目级认证信息配置,将认证信息配置到.gitlab-ci.yml配置文件
stages:
- build
variables:
DOCKER_AUTH_CONFIG: '{"auths": {"10.100.19.86:5000": {"auth": "YWRtaW46YWRtaW4="}}}'
test:
stage: build
tags:
- buildtest
image: 10.100.19.86:5000/centos:7-maven-lrn1.3
script:
- echo "image pull successed"
5,系统级配置
[[runners]]
environment = ['DOCKER_AUTH_CONFIG: '{"auths": {"10.100.19.86:5000": {"auth": "YWRtaW46YWRtaW4="}}}'']