gpt4 book ai didi

docker - 无法从 gitlab CI 拉取或推送到个人注册表

转载 作者:行者123 更新时间:2023-12-02 18:54:10 24 4
gpt4 key购买 nike

我实现了自己的 docker 注册表,并成功从本地主机(推送)和我的服务器(拉取)对其进行了测试。现在,我正在尝试从 CI 管道构建并推送图像:

build:
image: docker:18
services:
- docker:dind
stage: build
script:
- echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
- docker pull $CI_REGISTRY/website:latest
- docker build -t $CI_REGISTRY/website:latest .
- docker push $CI_REGISTRY/website:latest

我能够登录注册表:

$ echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded

当我尝试提取我的网站:最新图像时,我收到错误:

$ docker pull $CI_REGISTRY/website:latest
Error response from daemon: pull access denied for registry.gitlab.com/website, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

我在 CI/CD -> 变量 中正确配置了所有变量,但我可以在这里看到 registry.gitlab.com 作为我的注册表。我尝试将 CI_REGISTRY 重命名为 CI_REGISTRY_ADDRESS,因为我想,也许 gitlab 正在使用它作为系统变量,我无法替换它(即使当我使用此设置、变量和登录,与另一个项目中的方式相同,及其工作)。所以现在,我收到此错误:

$ echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY_ADDRESS
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password

我尝试用谷歌搜索解决方案,但没有找到任何有用的信息。我不确定为什么此设置适用于另一个项目而不适用于这个项目。也许我错过了一些东西,不确定是什么。有人可以帮我找出导致问题的原因以及如何配置个人注册表

编辑1:举例来说,相同的配置在我的另一个项目上运行良好:

$ echo -n $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded

成功登录后,我可以推送和拉取图像。

最佳答案

经过一番调查,我找到了根本原因。

我发现我的所有变量都是空的(我首先检查了,如果没有拼写错误):

echo "$PERSONAL_CI_REGISTRY_USER - $PERSONAL_CI_REGISTRY_PASSWORD - $PERSONAL_CI_REGISTRY"
- -

从 stackoverflow 上的 this 问题来看,它看起来像类似的问题 - protected 变量。所以我检查了我的变量,将它们设置为不 protected ,然后我能够在 CI 管道中回显它们:

$ echo "$PERSONAL_CI_REGISTRY_USER - $PERSONAL_CI_REGISTRY_PASSWORD - $PERSONAL_CI_REGISTRY"
registryuser123456 - registrypassword123456 - registry123456

protected 变量仅在 protected 分支或标签中可用 - 请参阅 doc

所以我以与在另一个项目中使用它相同的方式重命名了它:

docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

现在我可以毫无问题地登录注册表、拉取和推送。

关于docker - 无法从 gitlab CI 拉取或推送到个人注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66413971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com