以下内容在我的 .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,如下所示(以包含所有匹配的可能性)
{
"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": "..."
}
}
}
但是,每当尝试推送图像时,都会发生以下错误
$ 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 登录时,它起作用了。有人请告诉我我做错了什么让它与 DOCKER_AUTH_CONFIG 一起工作吗?
谢谢大家
问候 锡
最佳答案
要使用DOCKER_AUTH_CONFIG
的内容作为docker登录名,只需将其存储在$HOME/.docker/config.json
中,例如如下:
before_script:
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
引用号:https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#option-3-use-docker_auth_config
这允许使用单个配置来加载构建容器的图像,并从同一配置源访问构建内的注册表。
注意:这取代了docker登录
的执行
另请参阅:https://docs.docker.com/engine/reference/commandline/login/#privileged-user-requirement
关于docker - Gitlab DOCKER_AUTH_CONFIG 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51814625/