Gitlab DOCKER_AUTH_CONFIG 不起作用 [英] Gitlab DOCKER_AUTH_CONFIG not working

查看:16
本文介绍了Gitlab DOCKER_AUTH_CONFIG 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的 .gitlab-ci.yml

The following are in my .gitlab-ci.yml

stages:
  - build

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2

services:
  - docker:dind

build-image:
  image: docker:stable
  stage: build
  script:
    - docker build --no-cache -t repo/myimage:$CI_JOB_ID .
    - docker push repo/myimage:$CI_JOB_ID

我已经在 Gitlab 中设置了 DOCKER_AUTH_CONFIG,如下所示(包含所有匹配的可能性)

I've setup the DOCKER_AUTH_CONFIG in Gitlab like following (to contain all possibilities of matching)

{
    "auths": {
        "https://index.docker.io": {
            "auth": "...."
        },
        "https://index.docker.io/v1/": {
            "auth": "..."
        },
        "https://index.docker.io/v2/": {
            "auth": "..."
        },
        "index.docker.io/v1/": {
            "auth": "..."
        },
        "index.docker.io/v2/": {
            "auth": "..."
        },
        "docker.io/repo/myimage": {
            "auth": "..."
        }

    }
}

但是,每当尝试推送图像时,都会出现以下错误

However, whenever trying to push the image, the following error occurred

$ docker push repo/myimage:$CI_JOB_ID
The push refers to repository [docker.io/repo/myimage]
ce6466f43b11: Preparing
719d45669b35: Preparing
3b10514a95be: Preparing
63dcf81c7ca7: Waiting
3b10514a95be: Waiting
denied: requested access to the resource is denied
ERROR: Job failed: exit code 1

当我使用带有用户名/密码的 docker login 时,它起作用了.任何人都请告诉我我做错了什么让它与 DOCKER_AUTH_CONFIG 一起工作?

It worked when I use docker login with username/password. Anyone please show me what I did wrong to get it to work with DOCKER_AUTH_CONFIG?

谢谢大家

问候锡

推荐答案

DOCKER_AUTH_CONFIG 在您尝试从私有存储库中提取图像时有效.这是使用它的函数config 变量. 该函数仅由 getDockerImage 函数使用.

DOCKER_AUTH_CONFIG works when you are trying to pull the image from your private repository. Here is the function that uses that config variable. That function is only used by getDockerImage function.

因此,当您需要将图像推送到作业的 script 部分时,您需要在此之前执行 docker login 步骤.

So whenever you need to push your image inside your job's script section, you need the docker login step before that.

这篇关于Gitlab DOCKER_AUTH_CONFIG 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆