Push Docker Image to & Pull from DockerHub

0 / 131
Push to dockerhub
 

How to push and pull docker images from DockerHub

 

In this article we will learn from where the docker container images come from.

We will also learn how to pull and push image to Docker Hub.

To learn the basics & architecture of docker follow this article.

To learn how to install docker follow this article.

1. Obtaining an image from Docker Hub.

Docker Hub is where open Docker images are stored. When we run our first image by – docker run, it will first check  if this image already exists on our machine, and if it is not then it will be downloaded from Docker Hub.  

Docker image list

List docker images

 

We pull image from docker hub using

docker pull  

Docker pull

Docker pull

 

2. First lets create your own image locally using Dockerfile.

We have a html application which displays simple index page with contents –
1
This is the index page of html-app displayed from nginx container!


Below is the sample index.html page which we will copy to the container –

cat index.html

1
This is the index page of html-app displayed from nginx container!


Below is the Dockerfile which we will use –

cat Dockerfile

1
FROM nginx:latest


1
COPY ./index.html /usr/share/nginx/html/index.html


Now to build image locally run docker build command –

1
# docker ps


1
# docker build -t localhost/nginx-html-app:v1 .


1
# docker images
 

Docker images

Docker images

 

3. Create Docker Hub Account & repository

Log in on https://hub.docker.com/

Click on Create Repository.

Choose a name (e.g. prayags) and a description for your repository and click Create.

Log into the Docker Hub from the command line

docker login –username=prayags –email=prayag.rhce@gmail.com

As we can see in below image we have created repo – nginx-html-app  

Create docker repository

Create docker repository

 

4. Docker login

Login to docker hub using docker login  

Docker login

Docker login

 

 

5. Tag the docker image and push it

1
# docker tag localhost/nginx-html-app:v1 prayags/nginx-html-app:v1


1
# docker push prayags/nginx-html-app:v1
 

Docker push

Docker push

 

6. Check docker hub portal for our newly push image  

Check image in docker hub

Check image in docker hub

 

7. Pull our custom docker image from docker hub

1
# docker pull prayags/nginx-html-app:v1
 

Docker pull

Docker pull

 

1
# docker images
 

Comments

comments


***Linux, Cloud & Devops Architect & Technical Content Writer*** I am a Linux Enthusiast and Supporter/Promoter of Open Source Technology with over 12+ years of experience in Linux, Cloud and Devops. I am A Technical Content writer for various sites like : Hostbread & Golibrary