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?
- 311
- 2
- 4
- 7
3 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
- 28,263
- 13
- 94
- 127
-
Getting `Error response from daemon: Get https://10.10.10.50:5000/v1/users/: http: server gave HTTP response to HTTPS client` on docker login :( – ioleo Feb 02 '17 at 06:16
-
@loostro what docker version are you using? maybe this helps: http://stackoverflow.com/questions/38695515/can-not-pull-push-images-after-update-docker-to-1-12 – lvthillo Feb 02 '17 at 06:58
-
Works like a charm! – Camel Sep 17 '17 at 10:24
-
1@loostro, It is because the registry that you created is with HTTP endpoint. By default it expects HTTPS. The solution is to enable access by configuring it as insecure registry. { "insecure-registries" : [ "hostname.registry:5000" ] } – Amal G Jose Sep 05 '18 at 18:13
-
FYI config options are documented in https://github.com/distribution/distribution/blob/main/docs/configuration.md – Ivar Jun 28 '22 at 14:46
-
registry:2 does not have htpasswd ,seems like httpd:2 – zhengyitian Apr 06 '23 at 03:39
try to set this in your docker conf file ~/.docker/config.json
{
"auths": {
"https://localhost:5000/someimage": {
"auth": "username",
"email": "password"
}
}
}
- 5,669
- 4
- 35
- 53
When pushing containers or if your containers are loaded within a docker-compose file from a private docker repo you can use the docker login command beforehand.
docker login -u user -p password private.repository:5000
- 421
- 4
- 4