Docker : Docker-Registry (Authentication)2018/10/22 |
Configure Docker Private Registry which requires user authentication.
|
|
[1] |
On the Node which you run Registry Pod, Get SSL certificates, refer to here.
|
[2] | Install htpasswd command for adding users. |
root@dlp:~# apt -y install apache2-utils
|
[3] | Add any user you like. |
root@dlp:~# htpasswd -Bc /etc/docker/.htpasswd admin New password: Re-type new password: Adding password for user admin |
[4] | On this example, certificates are saved under [/etc/letsencrypt/live/(FQDN)] on Registry Node. Run Registry Pod with htpasswd file created above and certificates. |
root@dlp:~#
root@dlp:~# mkdir /etc/docker/certs.d root@dlp:~# cp /etc/letsencrypt/live/dlp.srv.world/fullchain.pem /etc/docker/certs.d/server.crt root@dlp:~# cp /etc/letsencrypt/live/dlp.srv.world/privkey.pem /etc/docker/certs.d/server.key
docker run -d -p 5000:5000 --restart=always --name registry \ -v /var/lib/registry:/var/lib/registry \ -v /etc/docker/certs.d:/certs \ -v /etc/docker:/auth \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/server.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/server.key \ -e REGISTRY_AUTH=htpasswd \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/.htpasswd \ -e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" \ registry:2 Trying to pull repository docker.io/library/registry ... 2: Pulling from docker.io/library/registry Digest: sha256:672d519d7fd7bbc7a448d17956ebeefe225d5eb27509d8dc5ce67ecb4a0bce54 Status: Downloaded newer image for docker.io/registry:2root@dlp:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES db00df47085f registry:2 "/entrypoint.sh /e..." 31 sec Up 29 sec 0.0.0.0:5000->5000/tcp registry |
[5] | It's OK to configure registry. Try to Push/Pull from your Private Registry. |
# login with a user you added root@node01:~# docker login dlp.srv.world:5000 Username: admin Password: Login Succeeded docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest b175e7467d66 6 days ago 109 MBroot@node01:~# docker tag nginx dlp.srv.world:5000/nginx root@node01:~# docker push dlp.srv.world:5000/nginx The push refers to a repository [dlp.srv.world:5000/nginx] 77e23640b533: Pushed 757d7bb101da: Pushed 3358360aedad: Pushed latest: digest: sha256:d903fe3076f89ad76afe1cbd0e476d9692d79b3835895b5b3541654c85422bf1 size: 948root@node01:~# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/nginx latest b175e7467d66 6 days ago 109 MB dlp.srv.world:5000/nginx latest b175e7467d66 6 days ago 109 MB |
Sponsored Link |