简体   繁体   中英

How To Pass Username & Password to Private Docker Registry For "htpasswd" authentication

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?

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 regisrty-admin:Password@123 https://my-registry.com:5000/v2/_catalog

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM