1

I have a docker registry:2 implemented using docker-compose with "htpasswd" authentication. This is working perfectly. I can log in to the registry using "docker login" command by passing the credentials on the terminal. All docker push/pull operations can be performed. However, the curl queries are failing with Authentication Error.

curl -s -H "Content-Type: application/json" -X POST -d '{"username": "regisrty-admin", "password": "Password@123"}' https://my-registry.com:5000/v2/_catalog

ERROR: {"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":[{"Type":"registry","Class":"","Name":"catalog","Action":"*"}]}]}

Docker-Compose.yml

version: '3.7'

services:
  my-registry:
    container_name: my-registry
    restart: always
    image: registry:2
    ports:
    - "5000:5000"
    environment:
      REGISTRY_HTTP_ADDR: 0.0.0.0:5000
      REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
      REGISTRY_HTTP_TLS_KEY: /certs/domain.key
      REGISTRY_AUTH: htpasswd
      REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
      REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
    volumes:
      - type: bind
        source: /opt/docker/registry/certs/
        target: /certs
      - type: volume
        source: registry_data
        target: /data
      - type: bind
        source: /opt/docker/registry/auth/
        target: /auth  

volumes:
  registry_data:

What is the correct way to use "htpasswd" credentials with CURL command for operations like listing registry images?

Efrat Levitan
  • 5,181
  • 2
  • 19
  • 40
Prashant Shetage
  • 167
  • 1
  • 3
  • 16
  • Probably you are looking for https://stackoverflow.com/questions/25969196/how-to-define-the-basic-http-authentication-using-curl-correctly – Tarun Lalwani Jun 10 '19 at 07:48
  • This is helpful but I came to know that, Passing Credential to Registry:2 through curl isn't supported as of now. This feature might be implemented in the latest versions of Docker registry:2 – Prashant Shetage Jun 11 '19 at 12:20
  • Can you provide source for this information @PrashantShetage ? – Orabîg Nov 24 '19 at 15:18

1 Answers1

2

You can authenticate a request to a private docker registry with curl like:

curl --user ${user}:${password} http://${domain}:${port}/v2/*

In your use case, this should be:

curl --user registry-admin:Password@123 https://my-registry.com:5000/v2/_catalog
Hadrien TOMA
  • 2,375
  • 2
  • 22
  • 32