Error response from daemon: pull access denied for registry.gitlab.com repository does not exist or may require 'docker login'

Viewed 9666

Dockerfile


FROM openjdk:8-jre-alpine

WORKDIR /app1/backend

COPY ./target/app1-backend.jar app1-backend.jar

ADD cloudfront_private_key.pem /host_files/

EXPOSE 9000

ENTRYPOINT [ "java", "-cp", "app1-backend.jar", "hsnbe.app1"]

docker-compose.yml

version: '3.4'

services:
  app1:
    logging:
      driver: awslogs
      options:
        awslogs-region: eu-west-1
    image: app1-server:development
    container_name: health_backend
    build:
      context: .
      dockerfile: ./build/DockerfileHS.dev
      target: app1
    restart: unless-stopped
    volumes:
      - ~/.ssh/health_backend_dev_cloudfront_private_key.pem:${HAPP_AWS_CLOUDFRONT_KEY_FILE_PATH:-/host_files/health_backend_dev_cloudfront_private_key.pem}
    ports:
      - ${APP1_PORT:-9000}:9000
    depends_on:
      - postgres
    links:
      - postgres

Error:

Reason CannotPullContainerError: Error response from daemon: pull access denied for registry.gitlab.com/app1/backend, repository does not exist or may require 'docker login'

What I've tried already:

  1. Docker Login Succeeded, but if I try to docker pull from registry returns: Error response from daemon: Get https://registry.gitlab.com/v2/app1/backend/manifests/latest: denied: access forbidden
2 Answers

TL;DR:

Check:

  1. Are you logged in? Look in ~/.docker/config.json for auths section
  2. The Auth token needs read-registry and write_registry scopes
  3. Does the project exist on GitLab? You can't push to arbitrary namespace
  4. Did you build / tag with the same name?

Access Denied for GitLab Container Registry

The access denied can be because the personal access token (PAT) which you are using does not have access to the project for this container registry.

  • The PAT must have read_registry scope to be able to pull, and also write_registry scope, if you want to push to the container registry
  • The GitLab User who owns the PAT must have permission to access the GitLab Project which owns this container registry:
    • For a docker push to a Private project, you need at least Developer access to that project
    • For docker pull, it is enough to be a Guest

You cannot use deploy tokens with the public API. They are only useful for CI/CD jobs.

Invalid tag name

Another reason for access denied can be if the project does not actually exist. You can't push to arbitrary namespaces in GitLab. In your example, the error says:

access denied for registry.gitlab.com/app1/backend

There is no "backend" project in @app1's namespace. This may not even be your namespace: http://gitlab.com/app1

There's not quite enough detail in the question, but as a guess, you should probably be doing this, substituting your username or group name for $GITLAB_USERNAME, and the project's namespace for $GITLAB_PROJECT_NAMESPACE:

docker build -t registry.gitlab.com/$GITLAB_USERNAME/$GITLAB_PROJECT_NAMESPACE/app1/backend:1.0

docker push registry.gitlab.com/$GITLAB_USERNAME/$GITLAB_PROJECT_NAMESPACE/app1/backend:1.0

I had installed gitlab-runner locally via apt-get and had the same issue.

I was able to fix the issue only I removed the installed gitlab-runner and reinstall it via curl

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

sudo apt-get install gitlab-runner
Related