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
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
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.
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.....
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.