Docker - Images

In Docker, everything is based on Images. An image is a combination of a file system and parameters. Let’s take an example of the following command in Docker.
docker run hello-world 

The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.
The Docker command is specific and tells the Docker program on the Operating System that something needs to be done.
The run command is used to mention that we want to create an instance of an image, which is then called a container.
The run command is used to mention that we want to create an instance of an image, which is then called a container.
Finally, "hello-world" represents the image from which the container is made.
Finally, "hello-world" represents the image from which the container is made.
Now let’s look at how we can use the CentOS image available in Docker Hub to run CentOS on our Ubuntu machine. We can do this by executing the following command on our Ubuntu machine −
sudo docker run -it centos /bin/bash

Note the following points about the above sudo command −
We are using the sudo command to ensure that it runs with root access.
We are using the sudo command to ensure that it runs with root access.
Here, centos is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.
Here, centos is the name of the image we want to download from Docker Hub and install on our Ubuntu machine.
─it is used to mention that we want to run in interactive mode.
─it is used to mention that we want to run in interactive mode.
/bin/bash is used to run the bash shell once CentOS is up and running.
/bin/bash is used to run the bash shell once CentOS is up and running.
To see the list of Docker images on the system, you can issue the following command.
docker images

This command is used to display all the images currently installed on the system.
docker images 

None
The output will provide the list of images on the system.
sudo docker images
When we run the above command, it will produce the following result −
From the above output, you can see that the server has three images: centos, newcentos, and jenkins. Each image has the following attributes −
TAG − This is used to logically tag images.
TAG − This is used to logically tag images.
Image ID − This is used to uniquely identify the image.
Image ID − This is used to uniquely identify the image.
Created − The number of days since the image was created.
Created − The number of days since the image was created.
Virtual Size − The size of the image.
Virtual Size − The size of the image.
Images can be downloaded from Docker Hub using the Docker run command. Let’s see in detail how we can do this.
The following syntax is used to run a command in a Docker container.
docker run image 

Image − This is the name of the image which is used to run the container.
Image − This is the name of the image which is used to run the container.
The output will run the command in the desired container.
sudo docker run centos
This command will download the centos image, if it is not already present, and run the OS as a container.
When we run the above command, we will get the following result −
You will now see the CentOS Docker image downloaded. Now, if we run the Docker images command to see the list of images on the system, we should be able to see the centos image as well.
The Docker images on the system can be removed via the docker rmi command. Let’s look at this command in more detail.
docker rmi

This command is used to remove Docker images.
docker rmi ImageID

ImageID − This is the ID of the image which needs to be removed.
ImageID − This is the ID of the image which needs to be removed.
The output will provide the Image ID of the deleted Image.
sudo docker rmi 7a86f8ffcb25 
Here, 7a86f8ffcb25 is the Image ID of the newcentos image.
When we run the above command, it will produce the following result −
Let’s see some more Docker commands on images.
This command is used to return only the Image ID’s of the images.
docker images 

q − It tells the Docker command to return the Image ID’s only.
q − It tells the Docker command to return the Image ID’s only.
The output will show only the Image ID’s of the images on the Docker host.
sudo docker images -q 
When we run the above command, it will produce the following result −
This command is used see the details of an image or container.
docker inspect Repository 

Repository − This is the name of the Image.
Repository − This is the name of the Image.
The output will show detailed information on the Image.
sudo docker inspect jenkins 
When we run the above command, it will produce the following result −

    70 Lectures 
     12 hours 

 Anshul Chauhan

    41 Lectures 
     5 hours 

 AR Shankar

    31 Lectures 
     3 hours 

 Abhilash Nelson

    15 Lectures 
     2 hours 

 Harshit Srivastava, Pranjal Srivastava

    33 Lectures 
     4 hours 

 Mumshad Mannambeth

    13 Lectures 
     53 mins

 Musab Zayadneh
 Print
 Add Notes
 Bookmark this page