Arun
Arun

Reputation: 339

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?

Upvotes: 9

Views: 24930

Answers (2)

yerlilbilgin
yerlilbilgin

Reputation: 3429

Use httpd:2 instead of registry for generating the password:

docker run \
  --entrypoint htpasswd \
  httpd:2 -Bbn testuser testpassword > auth/htpasswd

see: https://docs.docker.com/registry/deploying/#native-basic-auth

Upvotes: 3

Yuankun
Yuankun

Reputation: 7803

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.

Upvotes: 8

Related Questions