Pushing and Pulling images from Public repository in Docker

Filed Under: Random
Pushing And Pulling Images In Docker Hub

Hello, readers! In this article, we will be focusing on Pushing and Pulling images from a public repository in Docker.

So, let us begin!! 馃檪


Use of repositories in Docker

We make use of a Dockerfile to have all the configuration and related data packed into a single unit. We also create docker images for the docker files.

Now, the question is, where do we store these docker images for us to pull from? This is where repositories come into the picture.

A repository, also known as a registry, enables us to upload and store our Docker images. With this, we can upload as well as download the image for us as per the requirement.


Public and Private repositories

Basically, in the current scenario, we have two types of repositories/registries:

  1. Public Repository: Consider this registry as publicly available over the internet for all the users. That is, anyone can upload and download docker images from here for free. Docker offers us with Docker Hub portal where we can create our repositories and store our images.
  2. Private Registry: In private repositories, the data stored is private to our application and cannot be accessed by others unless an until they are not authorized for the same. Google Cloud offers us the Google Container registry and Azure offers us Azure Container Registry. These are paid services.

Now, we’ll learn to push and pull data from a public repository in Docker Hub.


Push an image to Public repository in Docker

Let us have a look at this step by step–

A] Create an account on the Docker Hub website.

B] Login with your above-created account.

C] Create a repository. Under the same, you would get the option to create a public or private repository. If we set the Visibility to Private, it won’t be accessible to anyone. For now, we set it to Public.

D] Once you create a repository, copy the docker pull and push command present on the screen (we would need that later).

Now, as we have created a repository, we would go ahead and tag the built image locally and push the image to the repository.

At first, we would need to login to the docker hub through CLI using the below command–

docker login

Then, it would prompt for a username and password. Enter the credential details of your docker hub account created in Step A.

  1. Tag the image:
docker tag imageID Repository-name 

Example:

docker tag d1165f221234 safamulani/demo

2. Push the docker image to our previously created repository:

docker push Repository-name 

Example:

docker push safamulani/demo

Output:

The push refers to repository [docker.io/safamulani/demo]

f22b99068db9: Preparing
f22b99068db9: Pushing
f22b99068db9: Pushing
f22b99068db9: Mounted from safamulani/demo
f22b99068db9: Pushing

latest: digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792 size: 525

Pulling image from Docker Public repository

In order to pull images from the public repository in Docker, make use of the below command:

docker pull repository-name

Example —

docker pull safamulani/demo

Output–

Using default tag: latest

latest: Pulling from safamulani/demo

Digest: sha256:1b26826f602946860c279fce658f31050cff2c596583af237d971f4629b57792

Status: Image is up to date for safamulani/demo:latest

docker.io/safamulani/demo:latest

Conclusion

By this, we have come to the end of this topic. Feel free to comment below, in case you come across any questions.

For more such posts related to Docker and Kubernetes, Stay tuned with us.

Till then, Happy Learning! 馃檪

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content