Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab CI + Docker Hub: requested access to the resource is denied

I'm trying to push my image to my docker repositoy repository using gitlab-ci, but i'm receiving the error:

denied: requested access to the resource is denied ERROR: Job failed: exit code 1

My .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

He build the image correctly, but when go to push

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

I change the repository name for the $REPOSITORY only for paste here.

I already give the right permissions on hub.docker.com for the user has make the docker login, has a colaborator on the repository.

Thanks

like image 249
augustoferronato Avatar asked Mar 08 '18 19:03

augustoferronato


1 Answers

use $CI_REGISTRY and $CI_PROJECT_PATH.

Example code:

- 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
like image 150
Hossein Avatar answered Sep 19 '22 19:09

Hossein