The best thing about the docker is its centralized docker registry. We can push and pull the images we require from it easily. But what if we want our own registry for keeping all the docker images we build. Keeping the images in self made docker registry will make it easy to manage and faster too in some cases and will be totally on yours control.
steps to create docker private registry:
There are some other ways to create docker private registry but we will follow what is also being clearly mentioned in the officials docker documentations page. The thing to understand is we will be running a docker container which we can use as a private registry. The cool thing here is there is another image available to create private registry. We run that image and create a registry container and keep it private with some authentication set. The name of the image is registry:2.
Start the docker container as you normally do:
$ docker run -d -p 5000:5000 --restart=always --name privateregistry registry:2
So the container will be running in a daemon mode and the name is privateregistry and is running locally in 5000 ports. Check with docker ps command to verify if registry:2 is running or not.
how to push images to private registry just made:
So our private registry docker container is up and running now we will push one image to it. For the sake of example we will simply pull alpine image change its tag and push to our private registry.
lets pull alpine image
docker pull alpine
we pulled the alpine image from official docker repo. Now we will make it ready to push to our local repository.
docker tag alpine localhost:5000/private-alpine
So here, we added new tag to the alpine image we recently pulled. The format to add the tag is hostname : port / imagename . So when pushing the image the docker will understand that it has to be pushed the particular hosts and ports.
Now we are totally ready to push our docker image to the local repository.
docker push localhost:5000/private-alpine
Pulling from the private registry
docker pull localhost:5000/private-alpine
The format for pulling is just the same as you pull from docker registry ,the only difference you will find is the image tag that has to be maintained to pushed to your private repository.
Watch the short video shows how it works:
The video is on progress and will be posted shortly:
Final Note on docker private registry:
We did this to demonstrate how to create your own docker private registry but for security purpose you have to implement some authentications so that only authorized users can make the entry and fetch from the registry build.