DOCKER REGISTRY

Docker pull <imagename> is a popular command we all are used to. But when we “pull” any public/private image where does docker magically pulls it from? It’s from the docker registry Docker Hub. Docker Hub is a well-known cloud-based docker registry maintained by Docker. It is a centralized public distribution center for Docker container images. Anyone is free to use Docker Hub to upload and distribute their docker container images.

Docker Registry

DOCKER HUB

Pushing (uploading) and pulling (downloading) images to and from Docker Hub is a fairly simple process. When you install docker in your machine it is configured with Docker Hub as your default container registry. So when you run your Docker push or Docker pull commands it automatically communicates with Docker Hub to push and pull the respective images.

PUSHING AND PULLING FROM DOCKER HUB

Docker Hub currently hosts more than 10000+ official docker images from various vendors. After starting Docker Daemon in your machine you can run Docker commands to push and pull any docker image.

PULL AN IMAGE

Pulling an image from Docker Hub is a fairly simple process.
Let’s say you want to pull the official ubuntu image. You can run

docker pull ubuntu

which will connect to docker Hub and will pull the official Ubuntu image with the latest tag. To pull a specific version you can specify the tag id to identify the specific docker image and pull the same. For instance, if you like to pull ubuntu version 20.04 you can run

docker pull ubuntu:20.04

which will pull ubuntu version 20.04 from the Docker Hub. For specific tags, you can check the official ubuntu docker hub repository and so on.

PUSH AN IMAGE

We have just pulled an image from Docker Hub let’s try pushing an image. Before pushing an image we need to log into our Docker Hub account and we need to have write access to the particular repository to which we would like to push our image.

To log into your Docker Hub account you can run docker login Docker Registry Now you have to enter your Dockerhub’s account credentials when prompted. You will see a login succeeded text printed in the console when you are successfully authenticated with Docker Hub.

Once authenticated we can push our desired image to our repository in Docker Hub. To push a local image to Docker Hub run the following command.

docker push username/repositoryname:tagname

Now your local image will be pushed to your account under the repository name provided with the respective tag.
To verify you can log into Docker Hub and check whether the image has been pushed or not.
And if you want to pull this particular image you can run

docker pull username/repositoryname:tagname

Now we have seen how we can push and pull a docker image to and from Docker Hub. But wait docker Hub isn’t entirely free though. You can technically host unlimited public images but you can have only one private repository at the moment. Don’t worry we have alternatives.

PRIVATE REGISTRY

Docker Hub is cool but what if we want to have our own private repository to store and distribute our docker container images privately and securely?
We can host our private docker registry in our own data center or cloud. We can use the official docker registry from Docker https://docs.docker.com/registry/ to achieve the same.

Docker registry can be pulled from the official Docker Registry repository from Docker Hub. To pull the registry run

docker pull registry

RUNNING OUR OWN REGISTRY

Now we have pulled the registry image. Let’s verify whether we have downloaded the Docker registry by running docker images.Now let’s run the registry. To run the registry run

docker run -d -p 5000:5000 --restart always --name registry registry:2

To verify the running container run

docker ps

Now our registry is running on port 5000 in our machine. Now we can push our images to our private registry. To push an image to our registry it is similar to pushing an image to the Docker hub but we need to specify our registry URL.To push a local image to our private registry run

docker push localhost:5000/imagename

UI FOR DOCKER REGISTRY

We have successfully run our private docker registry and pushed an image but its all done from the command line interface. What if we would like to access our registry from a web UI? Yes, there is quite a handful of GitHub projects which provide web UI for the docker registry.
https://github.com/Joxit/docker-registry-ui with ~1.1 stars
http://port.us.org/

You can find more here https://github.com/search?q=DOCKER+REGISTRY+UI

we will explore this segment in detail in another post.

ALTERNATIVES

We are not limited to Docker Hub or Docker registry to host and distribute our container images. We have the following alternatives which can host docker container images.

  1. Harbor https://goharbor.io/
  2. AWS ECS (Elastic Container Service) https://aws.amazon.com/ecs/
  3. Google Container Registry https://cloud.google.com/container-registry
  4. Azure Container Registry https://azure.microsoft.com/en-in/services/container-registry/
  5. RedHat Quay https://www.redhat.com/en/technologies/cloud-computing/quay

CONCLUSION

A container registry plays an inevitable role in our modern continuous integration & continuous delivery systems. Choosing a registry type is purely based on the use case and budget. As mentioned above there is a multitude of ways to host & distribute our container images.

CITATIONS

https://docs.docker.com/registry/
https://hub.docker.com/_/registry
https://en.wikipedia.org/wiki/Docker_(software)
https://goharbor.io/
https://aws.amazon.com/ecs/
https://cloud.google.com/container-registry
https://azure.microsoft.com/en-in/services/container-registry/
https://www.redhat.com/en/technologies/cloud-computing/quay

Share