I have been over numerous tutorials and I cannot get htpasswd to work in my private Docker Registry.
Here is my folder structure:
├── auth
│ └── htpasswd
├── certs
│ ├── registry.my.domain.crt
│ ├── registry.my.domain.csr
│ └── registry.my.domain.key
├── data
└── docker-compose.yml
Maybe it’s not important, but I generated my files like this:
In auth folder:
htpasswd -Bc htpasswd username
In certs folder:
openssl req -new -newkey rsa:2048 -nodes -keyout registry.my.domain.key -out registry.my.domain.csr
openssl x509 -req -days 365 -in registry.my.domain.csr -signkey registry.my.domain.key -out registry.my.domain.crt
My docker-compose file:
version: '3.9'
services:
registry:
container_name: registry
image: registry:2
restart: always
ports:
- "5000:5000"
environment:
- "REGISTRY_HTTP_TLS_CERTIFICATE:/certs/registry.my.domain.crt"
- "REGISTRY_HTTP_TLS_KEY:/certs/registry.my.domain.key"
- "REGISTRY_AUTH:htpasswd"
- "REGISTRY_AUTH_HTPASSWD_REALM:Registry"
- "REGISTRY_AUTH_HTPASSWD_PATH:/auth/htpasswd"
- "REGISTRY_STORAGE_DELETE_ENABLED=true"
volumes:
- "./data:/var/lib/registry"
- "./certs:/certs"
- "./auth:/auth"
deploy:
resources:
limits:
memory: 2048M
After I log in to registry.my.domain/v2/_catalog
it shows all repositories that I uploaded, and it doesn’t ask me for authentification.
I can also push and pull to the registry from any machine.
How can I secure it so that it asks for password?
2
Answers
I did the exact same scenario as you and it worked correctly. you can follow the below commands:
1- creating certificate:
2- Creating user and password for authentication
3- My docker compose file
4- run docker compose
5- Copy certificate (domain.crt) on destination client (node) and execute following commands:
6- Now, you can login to your private registry
7- Testing private registry
You are mixing the syntax on environment variables in the compose file. If you use an array, the separator is an
=
in a string. If you use a map, there’s a colon and space between the key and value. See the syntax of yaml files for more details of their syntax.This:
should be:
or