DockerHub is a free SaaS platform that can be used for storing and retrieving Docker images in public repositories. DockerHub also provides private registries, which is a paid service. However if we have a good hardware with enough storage and memory, we can also create our own Docker Registry server.
Docker Registry server can be created using the below steps:
It is assumed that you know basics of Docker.
- In a lab environment, it is good to choose a server hardware with min 2GB RAM and 50GB storage.
Install CentOS 7 and deploy Docker service
- The Docker Registry server can be deployed as a container, by using the image present in DockerHub public cloud registry
- As the data/images stored in the container are not persistent, it is advisable to mount a local storage folder to the container.
- Create a folder in the base host which can be attached to the Container that we are going to deploy.
[root@k8s-master ~]# mkdir /registry/storage
- Now run the following command to deploy the registry server container attaching the local folder to the container and exposing the listening port, 5000 to the public to access.
- [root@k8s-master ~]# docker run -d -p 5000:5000 -v /registry/storage:/var/lib/registry --restart=always --name MyRegistry registry:2
Creating and uploading an image to the newly created Docker Registry:
- Download a Docker image (Example CentOS) from the public repository of DockerHub and run it on the server where our Registry is deployed.
- Access the CentOS container, and add some data in the container.
- Commit the running container with the changes. Tag the committed container as “localhost:5000/myfound”
- Run the following command to upload the image present in the base server to the newly created Registry server
- [root@k8s-master ~]# docker push localhost:5000/myfund
Download an image from the newly created Docker Registry to a new server and deploy the image as a container: