Skip to main content

在 Docker 容器中运行 CI/CD 作业

要仔细多看几遍文档: https://gitlab.yitasoft.com/help/ci/docker/using_docker_images.md#use-statically-defined-credentials

如何让 job 的 image 使用私有 registry 的镜像

准备所需的 base64 编码版本 ${username}:${password} 并手动创建 Docker 配置 JSON。打开终端并执行以下命令:

# The use of "-n" - prevents encoding a newline in the password.
echo -n "my_username:my_password" | base64

# Example output to copy
bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ=

创建 Docker JSON 配置内容如下:

{
"auths": {
"registry.example.com:5000": {
"auth": "(Base64 content from above)"
}
}
}

Troubleshooting

【未解决】即使用户名密码都正确,但依然无法用私库 Image 执行任务

Running with gitlab-runner 15.0.0 (febb2a09) on Yitasoft Docker Runner 9ACKWbFs Preparing the "docker" executor 00:02 Using Docker executor with image registry.gitlab.yitasoft.com/yitasoft-team/docker-image/laravel-env:latest ... Authenticating with credentials from $DOCKER_AUTH_CONFIG Pulling docker image registry.gitlab.yitasoft.com/yitasoft-team/docker-image/laravel-env:latest ... WARNING: Failed to pull image with policy "always": Error response from daemon: Head "https://registry.gitlab.yitasoft.com/v2/yitasoft-team/docker-image/laravel-env/manifests/latest": unauthorized: HTTP Basic: Access denied (manager.go:203:0s) ERROR: Job failed: failed to pull image "registry.gitlab.yitasoft.com/yitasoft-team/docker-image/laravel-env:latest" with specified policies [always]: Error response from daemon: Head "https://registry.gitlab.yitasoft.com/v2/yitasoft-team/docker-image/laravel-env/manifests/latest": unauthorized: HTTP Basic: Access denied (manager.go:203:0s)