Docker series (Part 9): Create your docker image from an official image
Tags: docker
Published: 2022-06-10 05:48:45

okay..till now we have pulled some official images.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h1634pmxk6rinoqtjan1.png)
Carefully look at the nginx image : nginx which has a tag: latest & image id de2543b9436b.

You can see this from the official docker hub: https://hub.docker.com/_/nginx

Check its tags: ![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sa0lbik6mrn4ipoueiee.png)

Also , look at this : 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4lo5btzli78kea3r3cdo.png)

Here "mainline" , "latest", "1.21" etc means all the same.

In our system, we have nginx image with latest tag.
Lets pull a nginx image with mainline tag

If you go to docker hub, you can see this :

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4l1f308c0novuiyiwkjg.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xgz2nw00jgyaytssdrq.png)
While we pulled the nginx:mainline, you can see that few layers were already existed and others were pulled. SO, that is the benefit of having an image .

We previously had nginx image and thus few layers where existed. Now, as we pulled mainline tag, we just had to pull few layers.
 

now lets check the images

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6wi7egjx357wtgcubbb.png)
Check the mainline tag & latest tag has the same size 142mb.

Now lets create an image in docker hub using an official image

```
docker image tag <image to copy> <targeted image to be created>
```
tag is used to use the newest tag of that image of copy.

Oh! Before that, log in into your system using docker hub. SO that you can create an image and push it to docker hub.

```
docker login
```
then give your username & password.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/28ue2j1pxj5xdp00fpoz.png)

Now, lets create our image

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq2uzxgu6vm8d9pldd5z.png)
we have also checked our newly created image.
As our image will not be an official image, thus we have used "user_name/image name" format. 

Check carefully, nginx & mitul3737/nginx image has the same image ID: de2543b9436b
also they have the same tag : latest

This is because mitul3737/nginx has just copied nginx image and we told it to set the same tag (latest)

now, lets push it to our dockerhub profile

```
docker image push < your image>
```
    
 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w8o79ilrewexudgcira3.png)

You can see that the docker hub has this one

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0ed1ba0tkycp2e2n62u.png)
It has the latest tag with it.

Now, lets change the tag and of our image add another layer over it.

```
docker image tag <image to copy> <image where to copy>:<your_tag>
```
We have copied our mitul3737/nginx image and used it to create another image with tag "testing"


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io9a6bnfskq00r06nzwe.png)
 
YOu can see the nginx, mitul3737/nginx al has same image ID but mitul3737/nginx has latest & testing tag. These means that , they are all same image. Just copy of them with different names.

Now, lets push it to our docker hub

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldzmrwzzh1fll20czv6y.png)
Look carefully, the layers exists . This means that they are not re uploaded. while copying from mitul3737/nginx to mitul3737/nginx:testing, we copied everything and just gave it a new tag . Thus no new layers were added and we had nothing to uploadd.

In the docker hub:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98drknngepwxxr5z2cnt.png)

YOu can see that, under the mitul3737/nginx image, the layers are added. So, you can use latest one using mitul3737/nginx:latest command and use the testing one using
mitul3737/ngnx:testing

<img src="https://c.tenor.com/Tvd3VKwtse0AAAAC/cat-cute.gif">