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:
registry:
restart: always
image: registry:2
ports:
- 5000:5000
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
volumes:
- 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
dmaze
(David Maze)
May 3, 2016, 2:34pm
2
javapenguin:
volumes:
- auth:/auth
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
volumes:
- "./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 generate-htpasswd.sh
-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 generate-certificate.sh
User and password validate as well:
root@becc2dc2e950:/# htpasswd -v /auth/htpasswd gary
Enter password:
Password for user gary correct.
royalpay
(Royalpay)
February 8, 2018, 9:40am
4
Me too. Is question solved?
patrlind
(Patrlind)
March 7, 2018, 2:41am
5
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
bl4ckbird
(Bl4ckbird)
September 28, 2018, 5:32pm
6
Thats the right answer <3. Thank you so much!
janz1961
(Janz1961)
October 28, 2021, 11:43am
7
Thanks from me too. Got stuck with Docker Mastery course on Udemy. Now I can continue