Gitlab-runner job配置本地私服镜像

在GitLab中使用gitlab-runner执行job时遇到从私有Docker仓库拉取镜像失败的错误。解决方案包括设置环境变量DOCKER_AUTH_CONFIG,通过dockerlogin生成凭证,将Base64编码后的用户名密码放入配置文件中,无论是项目级还是系统级。配置完成后,runner应能成功访问私有仓库并拉取所需镜像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在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="}}}'']

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NettyBoy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值