Search This Blog

Saturday, March 31, 2018

Host private docker registry and connect to it ( Windows version)

If you don’t want to use dockerhub you can host your own private registry.

Get a registry image from docker hub and host it in a container as shown below.

image

$docker pull registry // also works from toolbelt

I used kitematic, you can dirctly pull from command line also, make sure you map port 5000,

where the docker registry api listens for calls.

so my registry now listening on

image


Lets connect to it and see the content.


Use curl to fire api call to registry endpoint


$ curl -v -X GET http://192.168.99.102:32768/v2/_catalog
Note: Unnecessary use of -X or --request, GET is already inferred.
* timeout on name lookup is not supported
*   Trying 192.168.99.102...
* Connected to 192.168.99.102 (192.168.99.102) port 32768 (#0)
> GET /v2/_catalog HTTP/1.1
> Host: 192.168.99.102:32768
> User-Agent: curl/7.46.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< Docker-Distribution-Api-Version: registry/2.0
< X-Content-Type-Options: nosniff
< Date: Fri, 30 Mar 2018 14:04:22 GMT
< Content-Length: 20
<
{"repositories":[]}
* Connection #0 to host 192.168.99.102 left intact


I used docker tool belt, i was on windows, it has curl on it.


So i could connect but there are no repositories currently.

Tag the image to puch to local repository

So the way to push a docker image locally to another private registry is by

naming it in such a way that the name has the url port and the image information.

so lets say we have hello-world image in > docker images

To pull it form dockerhub we do

docker run hello-world , it brings the image and run it and saves an image locally.

To push this hello-world image to our private repository , we will tag it like this.

> docker tag hello-world 192.168.99.102:32768/hello-world

Now it will automatically push it to the url  port and the image name specified, this is kind of a

trick to push images from local space to a private registry.


=======================


Lets try to push the image

> docker push 192.168.99.102:32768/hello-world

It ended up with error

 http: server gave HTTP response to HTTPS client

Multiple ways to solve this

If you natively on docker for windows, you can directly specify in preferences.

==============================

If you are using docker on unix, you can try to ssh into the minishift vm and add the daemon.json file in

the /etc/docker/daemon.json and sudo service docker restart(Should work)


// daemon.json file content

{
  "insecure-registries" : ["registry:5000"]
}


Tip *To ssh in to minishift vm or any docker vm running via tool belt on windows,you can do this

locate the id_rsa for that machine in the user profile folder and fire a ssh.

//

ssh -i ~/.minishift/machines/minishift/id_rsa docker@url


=============================

If you are on windows with toolbelt, you can ssh into your boot2docker vm and update the /var/lib/boot2docker/profile  and add docker opts for insecure registry as shown below

DOCKER_OPTS="--insecure-registry url:5000"

restart docker service and test again by pushing the image.

You should be able to push your image now.


Ref url

you can test your repo availability by  

$curl url:Port/v2/_ping

$curl url:Port/v2/_catalog


Please not , you can also pull repository image in same docker environment and refer to the

registry container on localhost:5000 , that way you should be able to push it easily, pushing to external ip could have this allow unsecure access issues, locally it should work just fine. I fired up a vagrant box for openshift and i could pull a registry image , run a registry locally and push on localhost:5000 just like that, hey vagrant is awsome.. I just started using it.

No comments:

Post a Comment