1 00:00:00,267 --> 00:00:03,534 As we know, that Docker Images command will list 2 00:00:03,534 --> 00:00:06,734 out all of the Docker Images stored in our machine 3 00:00:06,734 --> 00:00:10,301 with some basic information, such as image id, 4 00:00:10,301 --> 00:00:13,334 repository name, and image tag to identify 5 00:00:13,334 --> 00:00:16,267 different images. But what if we want to know more 6 00:00:16,267 --> 00:00:17,834 about any particular image? 7 00:00:18,234 --> 00:00:21,667 Well, for that, we have docker inspect command. 8 00:00:21,834 --> 00:00:25,467 'docker inspect' command returns information about every single 9 00:00:25,467 --> 00:00:28,834 Docker object who has contributed in the creation 10 00:00:28,834 --> 00:00:31,501 of a particular Docker Image, which can be very 11 00:00:31,501 --> 00:00:34,567 useful at the time of debugging. Let's list out 12 00:00:34,567 --> 00:00:37,234 all of the Ubuntu images available on our local 13 00:00:37,234 --> 00:00:41,101 machine by writing command docker images ubuntu. 14 00:00:41,634 --> 00:00:44,734 Here we are, we have four ubuntu images with 15 00:00:44,734 --> 00:00:47,734 different image tags under ubuntu repository. 16 00:00:47,934 --> 00:00:51,967 Let's inspect ubuntu:latest Docker image, 17 00:00:51,967 --> 00:00:55,334 type docker image inspect command followed by the 18 00:00:55,334 --> 00:00:58,701 image name that you want to inspect. We will type 19 00:00:58,701 --> 00:01:03,401 ubuntu:latest here. Press enter and as 20 00:01:03,401 --> 00:01:05,667 you can see, it has displayed the detailed 21 00:01:05,667 --> 00:01:10,234 information about the latest ubuntu image in JSON array. 22 00:01:10,567 --> 00:01:13,434 Here we can see the extended image Id of 23 00:01:13,434 --> 00:01:17,701 ubuntu:latest followed by Repo name and RepoDigests 24 00:01:17,701 --> 00:01:20,701 which is the 64 digit hex number. 25 00:01:21,367 --> 00:01:25,467 Next, we have Container identifier. Don't confuse it with 26 00:01:25,467 --> 00:01:28,467 the container running Ubuntu image, it is the 27 00:01:28,467 --> 00:01:31,601 intermediate container which Docker has created 28 00:01:31,667 --> 00:01:34,534 while building the Ubuntu image from Dockerfile. 29 00:01:34,534 --> 00:01:38,001 ContainerConfig is the configuration details 30 00:01:38,001 --> 00:01:40,334 about the same intermediate container which is 31 00:01:40,334 --> 00:01:43,834 stored as images metadata for reference. 32 00:01:43,834 --> 00:01:48,667 Next is the information related to scratch image and it's 33 00:01:48,667 --> 00:01:52,001 architecture which is used as the base image here. 34 00:01:52,001 --> 00:01:55,634 It also mentions the actual and VirtualSize of 35 00:01:55,634 --> 00:01:59,367 the final image. And at last, we have RouteFS 36 00:01:59,367 --> 00:02:03,034 identifier which shows digest of all intermediate 37 00:02:03,034 --> 00:02:05,667 layers of this image. If you want to access a 38 00:02:05,667 --> 00:02:09,267 specific detail about an image, you can format the 39 00:02:09,267 --> 00:02:12,533 output of docker inspect command, type docker inspect 40 00:02:12,533 --> 00:02:14,634 followed by the format tag. 41 00:02:14,634 --> 00:02:18,967 Provide arguments to format flag between inverted commas, 42 00:02:19,601 --> 00:02:22,967 RepoTags and RepoDigest separated by colon. 43 00:02:22,967 --> 00:02:27,067 At last, type docker image name, press enter and as 44 00:02:27,067 --> 00:02:31,967 a result, we got the RepoTag and RepoDigest of ubuntu:latest. 45 00:02:32,167 --> 00:02:33,934 We can also save the inspect 46 00:02:33,934 --> 00:02:37,467 results of an image to a file in JSON format for 47 00:02:37,467 --> 00:02:40,401 future references. Here we want to store the 48 00:02:40,401 --> 00:02:43,701 configuration details about this image in a text file. 49 00:02:43,701 --> 00:02:47,801 To do so, type 'docker image inspect --format', 50 00:02:47,934 --> 00:02:51,301 followed by json .Config in double inverted 51 00:02:51,301 --> 00:02:55,701 commas and curly braces, 'ubuntu' and store the 52 00:02:55,701 --> 00:03:01,767 result in 'inspect_report_ubuntu.txt' file. 53 00:03:02,001 --> 00:03:04,601 It is just a name that we have given to the file. 54 00:03:04,601 --> 00:03:06,801 You can give any name which you want. 55 00:03:07,367 --> 00:03:09,667 List out all of the available files. 56 00:03:09,767 --> 00:03:12,601 inspect report Ubuntu has been successfully 57 00:03:12,601 --> 00:03:15,767 created. Let's check out the contents of this file. 58 00:03:15,767 --> 00:03:18,534 Config details about latest Ubuntu image 59 00:03:18,534 --> 00:03:20,601 is available in the text file. 60 00:03:20,967 --> 00:03:23,967 If you remember, RootFS identifier in the 61 00:03:23,967 --> 00:03:27,034 inspection of ubuntu:latest image showed only the 62 00:03:27,034 --> 00:03:30,167 digest of all intermediate layers in the image. 63 00:03:30,301 --> 00:03:33,834 Based on only digests it is difficult to determine 64 00:03:33,834 --> 00:03:37,234 how the image was built, for that we have docker 65 00:03:37,234 --> 00:03:40,801 history command. 'docker history' will show us all 66 00:03:40,801 --> 00:03:43,534 the intermediate layers of an image. Let's find 67 00:03:43,534 --> 00:03:46,801 out the intermediate layers of this image. 68 00:03:46,801 --> 00:03:51,634 Type 'docker image history ubuntu' in terminal, we got 69 00:03:51,634 --> 00:03:54,934 all the intermediate layers for our latest Ubuntu image. 70 00:03:54,934 --> 00:03:57,534 These layers are stacked sequentially, 71 00:03:57,534 --> 00:04:00,234 starting from the base image at the bottom to the 72 00:04:00,234 --> 00:04:02,867 CMD layer at the top of the results. 73 00:04:02,867 --> 00:04:07,701 All the layers have their associated image ids, sizes and 74 00:04:07,701 --> 00:04:10,634 their creation time. To dig deeper into this, let 75 00:04:10,634 --> 00:04:13,367 us find history of one of the image which we have 76 00:04:13,367 --> 00:04:15,834 built on our local Docker host. We will find 77 00:04:15,834 --> 00:04:21,401 history of img_apache. Now type docker image history 78 00:04:21,401 --> 00:04:23,601 followed by the image name, which is 79 00:04:23,601 --> 00:04:27,567 img_apache and press enter. You might 80 00:04:27,567 --> 00:04:30,234 be wondering why some of the rows have image 81 00:04:30,234 --> 00:04:33,467 column in both the results contained missing 82 00:04:33,467 --> 00:04:36,734 and some of them have their image ids. As you may 83 00:04:36,734 --> 00:04:39,801 remember, the intermediate image ids are given to 84 00:04:39,801 --> 00:04:42,567 the layers created by Dockerfile instructions. 85 00:04:42,567 --> 00:04:46,167 And they can be used for caching purpose by our own 86 00:04:46,167 --> 00:04:49,367 Docker host. But if an image is pulled from Docker 87 00:04:49,367 --> 00:04:52,867 Hub, such caching would not happen and since it 88 00:04:52,867 --> 00:04:56,067 may cause environmental clashes. So we are not 89 00:04:56,067 --> 00:04:59,134 provided any image ids for intermediate layers 90 00:04:59,134 --> 00:05:03,867 of pulled images, all we can know is they exist. 91 00:05:04,767 --> 00:05:07,901 We have two types of intermediate images, 92 00:05:08,101 --> 00:05:11,234 which are easy to distinguish, one, which are built 93 00:05:11,234 --> 00:05:14,334 by some other Docker host and we have just used it 94 00:05:14,401 --> 00:05:17,934 as base image and the ones which are committed by 95 00:05:17,934 --> 00:05:21,634 our instructions. You can also identify them by 96 00:05:21,634 --> 00:05:24,401 the time they were committed. The base image 97 00:05:24,401 --> 00:05:27,234 intermediate layers are 17 months old, 98 00:05:27,267 --> 00:05:30,734 whereas the other ones are committed just a few hours ago.