Docker registry with htpasswd not working

Hi guys

I have been trying to get docker registry with authentication working without success.

I generated a password file with:

htpasswd -c htpasswd gary

Generated cert and key:

openssl req
-newkey rsa:4096 -nodes -sha256 -keyout domain.key
-x509 -days 365 -out domain.crt

Created my docker compose file:

restart: always
image: registry:2
- 5000:5000
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
- data:/var/lib/registry
- certs:/certs
- auth:/auth

Started up my registry

docker-compose up

When I try and login

docker login localhost:5000

I get the following error:

Error response from daemon: no successful auth challenge for https://localhost:5000/v2/ - errors: [basic auth attempt to https://localhost:5000/v2/ realm “Registry Realm” failed with status: 401 Unauthorized]

When I attached to the container and validate the password file

htpasswd -v htpasswd gary

It all works fine.

Any ideas

In current Docker Compose, this mounts the volume named auth in /auth in the container filesystem space. If you’re trying to mount the auth subdirectory of the directory containing the docker-compose.yml file, you need to say

  - "./auth:/auth"

If you docker-compose exec registry bash, do you see the /auth and /certs directories correctly?

Yes I can

root@becc2dc2e950:/# ls -l /auth/ && ls -l /certs/
total 8
-rwxrwxr-x 1 1000 1000 47 Apr 29 13:18
-rw-rw-r-- 1 1000 1000 43 Apr 29 13:43 htpasswd
total 12
-rw-rw-r-- 1 1000 1000 2126 Apr 29 13:44 domain.crt
-rw-rw-r-- 1 1000 1000 3272 Apr 29 13:44 domain.key
-rwxrwxr-x 1 1000 1000 120 Apr 29 13:43

User and password validate as well:

root@becc2dc2e950:/# htpasswd -v /auth/htpasswd gary
Enter password:
Password for user gary correct.

Me too. Is question solved?

I just had this problem, and it turns out I needed to use the bcrypt encryption for it to work.
sudo htpasswd -B [FILE] [USER]
Hope this helps

1 Like

Thats the right answer <3. Thank you so much!

Thanks from me too. Got stuck with Docker Mastery course on Udemy. Now I can continue :slight_smile: