DEV Community

Shahriyar Al Mustakim Mitul
Shahriyar Al Mustakim Mitul

Posted on

Docker series (Part 9): Create your docker image from an official image

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

Image description
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

Also , look at this :
Image description

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

Image description
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
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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

then give your username & password.
Image description

Now, lets create our image

Image description
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>
Enter fullscreen mode Exit fullscreen mode

Image description

You can see that the docker hub has this one

Image description
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>
Enter fullscreen mode Exit fullscreen mode

We have copied our mitul3737/nginx image and used it to create another image with tag "testing"

Image description

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
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

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

Top comments (0)