8

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

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • 2
    Possible duplicate of [denied: requested access to the resource is denied : docker](https://stackoverflow.com/questions/41984399/denied-requested-access-to-the-resource-is-denied-docker) – yamenk Mar 08 '18 at 20:30
  • `$REPOSITORY` is probably the issue. – Jonathon Reinhart Apr 25 '18 at 12:32
  • 1
    I am running up against this too. Weirdly, the login works fine; $ docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY WARNING! Using --password via the CLI is insecure. Use --password-stdin. 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 It almost looks related to this https://gitlab.com/gitlab-org/gitlab-ce/issues/23339 but I think this might be another issue. Are you able to push from – 4x0v7 Apr 25 '18 at 12:28
  • 1
    Just in passing...if you set `image` to `tmaier/docker-compose:latest` at the top of your `.gitlab-ci.yml` file, you won't have to install pip and then install Docker Compose. – Mark Birbeck Jan 17 '19 at 22:06

3 Answers3

6

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
Hossein
  • 3,755
  • 2
  • 29
  • 39
1

I think the issue is having the login within the before_script and not in the actual script section of the task.

It's a shame because it feels more 'correct' to me to factor the login part to the before_script section, and then to perform whatever Docker Hub-related actions are necessary in the script section.

But I'm afraid it doesn't work--each script section will need to include its own login step.

Mark Birbeck
  • 2,813
  • 2
  • 25
  • 12
1

I had the same error and i have changed "REGISTRY" varaibles adress which your registry address for example " registry.gitlab.com/ayil****/emre***** " then the problem is solved.....