Docker Image:how to work with it and its advantage

Docker Image:how to work with  it and its advantage
Written by Nilima PaulFebruary 16, 2022
14 min read
Nilima Paul

Technology Security Analyst

We will learn about Docker images in this article. We will display, remove, and download Docker images. We will examine how Docker images work and what their advantages are.

Introduction to Docker Images:

Docker Images comprise at least one read-just layer that incorporates our application code, libraries, and conditions expected to run the application. All in all, Images are unchanging documents that mean we can't make changes to the current picture straightforwardly; possibly we want to re-compose the Dockerfile and yet again construct the Docker Image with another Dockerfile or run a holder utilizing the picture and afterward make changes inside the compartment and submit the running compartment as a Docker Image. There are true Images accessible for well-known OS and programming like Ubuntu, CentOS, Nginx, nodejs, and so on, on, which is a public archive for Docker Images given by Docker. Anybody can pull a Docker picture from it; nonetheless, you should have a record on to push pictures to

How do Images work in Docker:

As mentioned above, an image consists of multiple layers; let’s understand it with an example. We want to create our own Nginx Docker Image.  It will consist of the below layers: –

  1. Base OS image(for ex. Ubuntu)
  2. Update the base image
  3. Install Nginx on Ubuntu
  4. Configure CMD or entry point to run Nginx when any container gets created with this image.


docker build -t <name of the docker image>:<tag> <path of the Dockerfile>


docker build -t my_nginx.


The above command will build a new Image with the name my nginx, and the daemon considers the ‘latest’ tag as it is not specified and check the current working directory for Dockerfile.

  • It will download a ubuntu picture first and run a moderate holder utilizing ubuntu Image
  • Update the ubuntu picture and submit another middle of the road Image and eliminate the halfway compartment.
  • Run another moderate holder utilizing Image submitted in sync 2.
  • A similar interaction will go on till the last line of the Dockerfile.
  • The last dedicated Image will be the last Image, and the daemon will give it a name and tag.

Below is the syntax to manage the image: –

docker image <command>
How to display Docker Images:

Orders to show pictures that are accessible on have locally, all underneath orders will give us a similar result: -

docker picture ls

docker pictures

docker picture list

There are various choices that we can use with the above order. For instance, to list all pictures, including transitional pictures, we want to utilize - a choice with the above orders: -

How to download Docker Images:

We use the pull command to download Images locally.


docker pull <image_name>


docker pull ubuntu

If we have to download a specific tag or version of any Image, we need to specify the tag while pulling the Image.


docker pull <image_name>:tag


docker pull ubuntu:xenial

If we have a private registry, then we need to give the registry name, most probably the hostname on which the registry container is running. Let’s understand it with an example.

1. First, we need to create a private registry using the below command: –

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

Explanation:above order makes a compartment with a picture vault and open it to port 5000 on the host as well as inside the holder and set the restart choice to continuously, and that implies the daemon will restart the holder without fail on the off chance that the compartment isn't running.

2. Retag existing Docker image with localhost:5000 as below: –

docker image tag ubuntu localhost:5000/ubuntu

Explanation: above command retags the exiting ubuntu image with localhost:5000/ubuntu as we have exposed the container to localhost on 5000 port.

Note: – Docker image name must start with localhost:5000, and after / we can name it as we want, here we keep ubuntu itself.

3. Let’s push the image to our private registry: –

docker push localhost:5000/ubuntu

Explanation: – above command pushes the newly tagged Docker image to our private registry that is running as a container.

4. Now we remove the Docker image available locally: –

docker image rm localhost:5000/ubuntu

Explanation: above command will untag the ubuntu Images that we have just tagged in the above step; however, we have already pushed this image to our private registry so we can run a container using ‘localhost:5000/ubuntu’.

5. Run a container using ‘localhost:5000/ubuntu’ as shown below: –

docker run -d localhost:5000/ubuntu sleep 3000

Explanation:In the above snapshot, you can see daemon is pulling the image from ubuntu instead of library/ubuntu. Below are the containers that are running currently. We can see one of them is running using the ‘localhost:5000/ubuntu’ image.

How to remove Docker Images:

We can remove any Docker Images using the ‘rm’ command if it is not referenced by any container; However, we can force remove the Images even if it is referenced by any container.


docker image rm <image_name>


docker image rm <image_id>


docker image rm alpine
docker image rm 82f67be598eb

Explanation: In the above depiction, the elevated Docker picture has been taken out with the most recent tag. Keep in mind, in the event that we don't determine the tag, it will take the most recent tag. In the underneath preview, we have an elevated picture with tag 3.9; assuming that we attempt to eliminate it with the order 'docker picture rm snow capped', it will toss a mistake 'No such picture: high'; possibly we want to determine the tag or eliminate involving Image ID as beneath: -

docker image rm alpine:3.9


docker image rm 82f67be598eb

As mentioned above, we can remove the Images even if it is referenced by any container that might be in the running or excited state. We have to use -f to forcefully remove any Docker Image as below: –


docker image rm -f <image_name>or<image_id>


docker image rm -f ubuntu

In the above preview, we can see there is a compartment referring to the ubuntu picture, and in the event that we attempt to just eliminate the picture, the daemon is whining about struggle; notwithstanding, in the following order, utilizing the - f  option ready to eliminate the ubuntu Image.


1. Compactness - Images are convenient as it incorporates every one of the expected conditions and libraries to the application, so it runs identical way on any stage like Linux, Windows, Cloud and even Raspberry Pi.

2.  Lightweight - It has a multi-facet record framework that makes pictures incredibly lightweight in light of the fact that each layer incorporates just contrasts from different layers.

3.   Consistency - Images have strong qualities of powerlessness to change; that is called changelessness. It is exceptionally helpful while testing new elements of any application as it won't break our current picture. In the case of something turns out badly, we can run the application again involving the current picture as that is unaltered. Unchanging nature additionally gives the consistency that implies on the off chance that the application is running true to form in the test climate, it will run in similar way in different conditions too.

4.   Sharing - We can store Images in an archive. We have a public storehouse given by Docker itself; nonetheless, we can make our own archive on and keep our Images secretly on the off chance that we need. We can make our own private library too. It assists us with sharing pictures all the more without any problem

5.   Secure - Docker Images are secure. Each Image has its hash esteem. We can likewise carefully sign the Images, so in the event that somebody attempts to run a holder utilizing an unsigned picture, the daemon won't begin the compartment.


Docker Images are the central object of Docker. We can't envision Docker without pictures. It is the underlying thing that we want to work with Docker after introducing it. Pictures are like layout or depiction of a VM yet not restricted to as it enjoys more upper hands over format or preview.

Docker Images
Docker secrets
Was this blog helpful?
You must be Logged in to comment
Code Block

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance