AJNOURI / Docker_Certified_Associate_Certification

Preparation for Docker Certified Associate certification exam.
MIT License
4 stars 2 forks source link

Cannot login to the private registry #8

Closed AJNOURI closed 6 years ago

AJNOURI commented 6 years ago

Configuring private docker registry with self-signed certification.

Connection to the new registry is refused :

here is the prior configurations:

mkdir certs
mkdir auths

openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/dockerrepo.key -x509 -days 365 -out certs/dockerrepo.crt -subj /CN=myregistry.ajnouri.com                                                                       

Generating a 4096 bit RSA private key ............................................................................................................................++ .....................................................................................................................++ writing new private key to 'certs/dockerrepo.key'


mkdir -p /etc/docker/certs.d/myregistrydomain.com:5000

cd /etc/docker/certs.d/myregistrydomain.com\:5000 

cp /home/certs/dockerrepo.crt   ca.crt
make sure root owns ca.crt

docker pull registry:2

docker run --entrypoint htpasswd registry:2 -Bbn test password > auth/htpasswd

docker run -d -p 5000:5000 -v /etc/docker/certs.d/myregistry.ajnouri.com\:500/certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/home/ajn/certs/dockerrepo.crt -e REGISTRY_HTTP_TLS_KEY=/home/ajn/certs/dockerrepo.key -v /etc/docker/certs.d/myregistry.ajnouri.com\:500/auth:/auth -e REGISTRY_AUTH=htpasswd -e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/home/ajn/auth/htpasswd registry:2

And when trying to login:

[root@dockerstd1 myregistry.ajnouri.com:500]# docker login myregistry.ajnouri.com:5000/mybusybox

Username: test Password: Error response from daemon: Get https://myregistry.ajnouri.com:5000/v2/: dial tcp 192.168.0.149:5000: getsockopt: connection refused

AJNOURI commented 6 years ago

After some inspection, I found that I have created the htpasswd file under /home/ajn/auth with root privivileges:

[ajn@dockerstd1 ~]$ ls -la auth/htpasswd -rw-r--r--. 1 root root 67 Jan 24 23:49 auth/htpasswd [ajn@dockerstd1 ~]$

Might be the issue. So I removed the file and all images:

docker stop `docker ps -q` 
docker rm `docker ps -a -q` 
docker rmi `docker images -q` -f

docker pull registry:2

docker run --entrypoint htpasswd registry:2 -Bbn test password > auth/htpasswd

[ajn@dockerstd1 ~]$ docker run -d -p 5000:5000 -v /home/ajn/certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/dockerrepo.crt -e REGISTRY_HTTP_TLS_KEY=/certs/dockerrepo.key -v /home/ajn/auth:/auth -e REGISTRY_AUTH=htpasswd -e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" -e REGISTRY_AUTH_HTPASSWD_PATH=/home/ajn/auth/htpasswd registry:2

c7d88b8e2673bdc32bea2fae57c0917409c135b0de291cf99691188034beb34d

[ajn@dockerstd1 ~]$ docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES c7d88b8e2673        registry:2          "/entrypoint.sh /etc_"   14 seconds ago      Up 13 seconds       0.0.0.0:5000->5000/tcp   compassionate_neumann [ajn@dockerstd1 ~]$

So far looks OK.

docker pull busybox docker tag busybox myregistry.ajnouri.com:5000/my-busybox

But when trying to log: docker login myregistry.ajnouri.com:5000/my-busybox

Username: test Password: Error response from daemon: Get https://myregistry.ajnouri.com:5000/v2/: x509: certificate signed by unknown authority

AJNOURI commented 6 years ago

After correcting several issues:

Still having an error when connecting to the registry:

[ajn@dockerstd1 ~]$ docker login myregistry.ajnouri.com:5000/my-busybox

Username: test Password: Error response from daemon: Get https://myregistry.ajnouri.com:5000/v2/: http: server gave HTTP response to HTTPS client

===> this is solved here https://github.com/AJNOURI/Docker_Certified_Associate_Certification/issues/9!!!

AJNOURI commented 6 years ago

Ok, solved the issue. I 've tried to spot the issues I encountered and that was a conglomerate of errors:


[ajn@dockerstd1 ~]$docker login myregistry.ajnouri.com:5000/my-busybox

Username: test Password: Login Succeeded