Gitlab CI + Docker Hub:拒绝了对资源的请求访问

时间:2018-03-08 19:03:35

标签: docker gitlab gitlab-ci-runner

我正在尝试使用gitlab-ci将我的图像推送到我的docker repositoy存储库,但我收到错误:

拒绝:拒绝请求访问资源 错误:作业失败:退出代码1

我的 .gitlab-ci.yml

# This file is a template, and might need editing before it works on your project.
# Official docker image.
image: docker:latest

services:
  - docker:dind

before_script:
   - docker version
   - docker-compose version
   - docker login -u $USER -p $PASS index.docker.io


build-master:
  stage: build
  script:
    - apk add --no-cache py-pip
    - pip install docker-compose    
    - docker build --pull -t index.docker.io/$REPOSITORY .
    - docker push index.docker.io/$REPOSITORY
  only:
    - master
  tags:
  - docker

build:
  stage: build
  script:
    - docker build --pull -t index.docker.io/$REPOSITORY:latest .
    - docker push index.docker.io/$REPOSITORY:latest
  except:
    - master
  tags:
  - docker

他正确地构建了图像,但是当去推动

The push refers to repository [docker.io/$REPOSITORY]
fc57a6fc4d42: Preparing
09b261acf68f: Preparing
04ea2928643d: Preparing
1132926ce5ae: Preparing
de09db5a8cb2: Preparing
0b75a2e7b59f: Preparing
d01d9d1902f1: Preparing
3dab7cdf2eed: Preparing
1da4e8fff32b: Preparing
23c522961836: Preparing
a51421a28d33: Preparing
8b1c06910686: Preparing
30e8a3d88591: Preparing
fd8fae5cd65a: Preparing
6b68dfad3e66: Preparing
cd7100a72410: Preparing
0b75a2e7b59f: Waiting
d01d9d1902f1: Waiting
3dab7cdf2eed: Waiting
1da4e8fff32b: Waiting
23c522961836: Waiting
a51421a28d33: Waiting
8b1c06910686: Waiting
30e8a3d88591: Waiting
fd8fae5cd65a: Waiting
6b68dfad3e66: Waiting
cd7100a72410: Waiting
denied: requested access to the resource is denied
ERROR: Job failed: exit code 1

我只更改$ REPOSITORY的存储库名称以便粘贴。

我已经在hub.docker.com上给出了正确的权限,因为用户已经登陆了docker,在存储库上有一个colaborator。

由于

3 个答案:

答案 0 :(得分:1)

我遇到了同样的错误,并且我更改了您的注册表地址(例如“ registry.gitlab.com/ayil****/emre*****”)的“ REGISTRY”变量地址,因此问题得以解决。 ...

答案 1 :(得分:1)

使用$CI_REGISTRY$CI_PROJECT_PATH

示例代码:

- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH
- docker build -t $CI_REGISTRY/$CI_PROJECT_PATH/name:latest
- docker push $CI_REGISTRY/$CI_PROJECT_PATH/name:latest

答案 2 :(得分:0)

我认为问题出在该任务的before_script中而不是实际的script部分中。

这很遗憾,因为我觉得更“正确”是将登录部分分解为before_script部分,然后执行script部分中必要的与Docker Hub相关的任何操作。

但是我担心它不起作用-每个script部分都需要包含自己的登录步骤。