mkdir registry
cd registry/
mkdir auth
apt-get install apache2-utils
htpasswd -Bbn test_user test_password > auth/htpasswd
Important
Validate using cat auth/htpasswd
mkdir auth
docker run --entrypoint htpasswd httpd:2 -Bbn test_user test_password > auth/htpasswd
docker run -d \
-p 5000:5000 \
--restart=always \
--name registry \
-v "$(pwd)"/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
registry:2.7.0
docker pull busybox
docker tag busybox:latest localhost:5000/busybox
docker login localhost:5000
Or simply docker login -u test_user -p test_password localhost:5000
docker push localhost:5000/busybox
Note
Credentials are saved in ~/.docker/config.json
export DOCKER_AUTH_CONFIG=`cat ~/.docker/config.json`
Important
Validate using echo "$DOCKER_AUTH_CONFIG"
{
"auths": {
"registry.example.com:5000": {
"auth": "bXlfdXNlcm5hbWU6bXlfcGFzc3dvcmQ="
}
}
}
docker tag redis:latest localhost:5000/redis:latest
docker push localhost:5000/redis:latest
You should now be able to test using localhost:5000/redis:latest
✨
Reference:
https://stackoverflow.com/questions/38247362/how-i-can-use-docker-registry-with-login-password
https://stackoverflow.com/questions/62531462/docker-local-registry-exec-htpasswd-executable-file-not-found-in-path