CREATING A PRIVATE DOCKER REGISTRY

ABOUT REGISTRY
A registry is a repository of docker images. Docker by default points to Public Docker Registry which is also called as Docker Hub. docker search
would list results from docker hub and more information about image is available on hub.docker.com
You can upload your docker images on Docker Hub which would be available for public. You can also create your own registry if you don't want to make it public or want a it in your premises available privately for your organisation or development environment.
CREATE REGISTRY
This one-liner will deploy your own private docker registry.
docker run --name=docker-registry -d -v /opt/registry:/var/lib/registry:Z -p 5000:5000 registry
-d
: will demonize the container-v /opt/registry:/var/lib/registry:Z
: Will make/var/lib/registry
folder persistent on your host at/opt/registry
and:Z
will set appropriate SELinux context on/opt/registry
-p 5000:5000
: will forward port 5000 from your host to port 5000 of your registry container.

Note: This registry uses v2 APIs, so you will have to use Docker version 1.6.0+ to pull and push images.
TEST IT
CREATE A DOCKERFILE
WITH THE BELOW CONTENT
FROM docker.io/library/alpine
CMD ["echo","Hello World!"]
BUILD YOUR IMAGE USING DOCKER BUILD
[root@localhost ~]# docker build -t localhost:5000/hello .
Sending build context to Docker daemon 2.048 kB
Step 1 : FROM docker.io/library/alpine
---> 4a415e366388
Step 2 : CMD echo Hello World!
---> Running in bda8cb469d6a
---> 9d586b88dd82
Removing intermediate container bda8cb469d6a
Successfully built 9d586b88dd82
LET'S PUSH IT USING DOCKER PUSH
[root@localhost ~]# docker push localhost:5000/hello
The push refers to a repository [localhost:5000/hello]
23b9c7b43573: Pushed
latest: digest: sha256:84767a295c57bfd0a43072240790f105b192d60fbd836cb1df12badb3a1b4cf0 size: 528
We have created a persistent storage for our registry folder so you can see it in your /opt/registry folder.
[root@localhost ~]# ls -l /opt/registry/docker/registry/v2/repositories/
total 0
drwxr-xr-x. 5 root root 52 Mar 8 08:09 hello
Thats it :)
Like it? Click here to Tweet your feedback