Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set username and password for our own docker private registry?

I was able to run repository using $docker container run -itd --publish 5000:5000 registry But, I am not asked for username and password when I pull or push the image to that repository.

How to set username and password for our own docker private registry and how to use them in Dockerfile and docker-compose when we want to use the image from that repository?

like image 799
Arun Avatar asked Apr 26 '18 01:04

Arun


People also ask

Can I host my own docker registry?

Private and Public Docker RegistriesThe Docker Hub can host our images, but they will be publicly available. In most cases, images contain all the code and configuration needed to run an application. In that case, we can either use a Docker Hub private account or set up a private Docker registry on a machine.


1 Answers

How to set username and password for our own docker private registry?

There are couple ways to implement basic auth in DTR. The simplest way is to put the DTR behind a web proxy and use the basic auth mechanism provided by the web proxy.

To enable basic auth in DTR directly? This is how.

  1. Create a password file containing username and password: mkdir auth && docker run --entrypoint htpasswd registry:2 -Bbn your-username your-password > auth/htpasswd.
  2. Stop DTR: docker container stop registry.
  3. Start DTR again with basic authentication, see commands below.

Note: You must configure TLS first for authentication to work.

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 \
  -v `pwd`/certs:/certs \
  -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
  -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
  registry:2

How to use them when we want to use the image from that repository?

Before pulling images, you need first to login to the DTR:

docker login your-domain.com:5000

And fill in the username and password from the first step.

like image 170
Yuankun Avatar answered Nov 15 '22 05:11

Yuankun