Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can use docker-registry with login/password?

I have my docker-registry in localhost and I can pull/push with command: docker push localhost:5000/someimage How I can push it with command like docker push username@password:localhost:5000/someimage?

like image 220
kvendingoldo Avatar asked Jul 07 '16 13:07

kvendingoldo


People also ask

How do I log into docker repository?

You can log into any public or private repository for which you have credentials. When you log in, the command stores credentials in $HOME/. docker/config. json on Linux or %USERPROFILE%/.

Which command is used for login to a self hosted registry?

To start using a private Docker Registry a user usually should run the docker login command and set a username and password that will be cached locally.


2 Answers

This solution worked for me: First I've created a folder registry from in which I wanted to work:

$ mkdir registry
$ cd registry/

Now I create my folder in which I wil store my credentials

$ mkdir auth

Now I will create a htpasswd file with the help of a docker container. This htpasswd file will contain my credentials and my encrypted passwd.

$ docker run --entrypoint htpasswd registry:2 -Bbn myuser mypassword > auth/htpasswd

To verify

$ cat auth/htpasswd
myuser:$2y$05$8IpPEG94/u.gX4Hn9zDU3.6vru2rHJSehPEZfD1yyxHu.ABc2QhSa

Credentials are fine. Now I have to add my credentials to my registry. Here for I will mount my auth directory inside my container:

docker run -d -p 5000:5000 --restart=always --name registry_private  -v `pwd`/auth:/auth  -e "REGISTRY_AUTH=htpasswd"  -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm"  -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd"  registry:2

TEST:

$ docker push localhost:5000/busybox
The push refers to a repository [localhost:5000/busybox]
8ac8bfaff55a: Image push failed
unauthorized: authentication required

authenticate

$ docker login localhost:5000
Username (): myuser
Password:
Login Succeeded

Retry the push

$ docker push localhost:5000/busybox
The push refers to a repository [localhost:5000/busybox]
8ac8bfaff55a: Pushed
latest: digest: sha256:1359608115b94599e5641638bac5aef1ddfaa79bb96057ebf41ebc8d33acf8a7 size: 527

Credentials are saved in ~/.docker/config.json:

cat ~/.docker/config.json

{
    "auths": {
        "localhost:5000": {
            "auth": "bXl1c2VyOm15cGFzc3dvcmQ="
        }
    }

Don't forget it's recommended to use https when you use credentials.

Here is a blog on how to use TLS (self signed certs with this approach): https://medium.com/@lvthillo/deploy-a-docker-registry-using-tls-and-htpasswd-56dd57a1215a

like image 81
lvthillo Avatar answered Sep 29 '22 05:09

lvthillo


try to set this in your docker conf file ~/.docker/config.json

{
        "auths": {
                "https://localhost:5000/someimage": {
                        "auth": "username",
                        "email": "password"
                }
        }
}
like image 41
ZEE Avatar answered Sep 29 '22 04:09

ZEE